home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 44 / Amiga Format CD44 (1999-08-26)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-10].iso / -in_the_mag- / basics / blitz / crazy8.src.lha / C8.source / Crazy8.src next >
Text File  |  1999-05-23  |  75KB  |  2,670 lines

  1. ; Crazy 8's
  2. ; Ver 2.92
  3. ; by Curt Esser
  4. ; 113 Pauline Ave
  5. ; Crystal Lake
  6. ; Il. 60014
  7. ; camge@ix.netcom.com
  8. ; last modified  May 15, 99
  9.  
  10. WBStartup       ;run from WorkBench!
  11. NoCli
  12. c8$=Chr$(128)+Chr$(129)+Chr$(130)+Chr$(131)+Chr$(132)
  13. v$="$VER: Crazy8 v2.92 (15.05.99) by Curt Esser"
  14. about$=c8$+"|"
  15. about$+ "2.92|"
  16. about$+ "May 15, 1999|"
  17. about$+ Chr$(135)+" 1996 - 1999|"
  18. about$+"by Curt Esser|"
  19.  
  20. ScreenPens 1,4,0,3,7,3,7
  21.  
  22. If NTSC=True
  23.   vrate=60      ;adjust for NTSC or PAL Vblank rate
  24. Else
  25.   vrate=50
  26. EndIf
  27.  
  28. ;---------------------------------------------------------------
  29.  
  30. ourpath$=ProgDir$  ;get our program's directory
  31.  
  32. If NumPars         ;if we were called by a prefs file!
  33.   pref$=Par$(1)
  34. Else
  35.   pref$=ourpath$+"/default.8's"
  36. EndIf
  37.  
  38. ex$="Assign Crazy: "+Chr$(34)+Chr$(34)  ;so we can load the
  39. Execute_ ex$,0,0                        ;game font direct from
  40.                                         ;our fonts/ drawer
  41. ex$="Assign FONTS: Crazy:fonts/ ADD"    ;instead of putting it
  42. Execute_ ex$,0,0                        ;into SYS:Fonts/
  43.  
  44. font$="C8.font"
  45. Gosub newfont
  46.  
  47. .procedures
  48.  
  49. ;---------------------------------------------------------------
  50.  
  51. ;Kick 2.xx compatible GTGetString command
  52.  
  53. Function.s GTGetStr{lst.w, gdt.w}
  54.   *gad.Gadget = GTGadPtr(lst, gdt)
  55.   *si.StringInfo = *gad\SpecialInfo
  56.   a$= Peek$(*si\_Buffer)
  57.   Function Return a$
  58. End Function
  59.  
  60. ;---------------------------------------------------------------
  61.  
  62. Function SetMouse { x.w,y.w,button.w}
  63.   AbsMouse x,y
  64.   If button
  65.     ClickButton 0
  66.   EndIf
  67. Function Return -1
  68.  
  69. End Function
  70.  
  71. ;----------------------------------------------------------------
  72.  
  73. ; fixes the GetAShape bug on 030 + processors
  74. ; the problem: the "cookie" mask gets thrashed sometimes
  75. ; this will fix it - use in place of GetAShape
  76.  
  77. Statement GetShape{shapenumber.w,x.w,y.w,width.w,height.w}
  78.   AutoCookie Off
  79.   Free Shape shapenumber
  80.   GetaShape shapenumber,x,y,width,height
  81.   AutoCookie On
  82.   CacheClearU_
  83.   MakeCookie shapenumber
  84. End Statement
  85.  
  86. ;----------------------------------------------------------------
  87.  
  88. Function$ Language {}         ;get name of preferred language
  89.                               ;by James Boyd
  90.   l$="locale.library"
  91.   *loclib=OpenLibrary_ (&l$,0)
  92.   If *loclib
  93.     *locale.Locale=OpenLocale_(0)
  94.     If *locale
  95.       country$=Peek$(*locale\loc_LanguageName)
  96.       CloseLocale_ *locale
  97.     EndIf
  98.   CloseLibrary_ *loclib
  99.   EndIf
  100.   If country$
  101.     country$=Left$(country$,Len(country$)-9)
  102.   Else
  103.     country$="English"
  104.   EndIf
  105.   Function Return country$
  106. End Function
  107.  
  108. ;---------------------------------------------------------------
  109.  
  110. Function$ ReadLoc {}  ;reads a string from our locale text files
  111.                       ;ignores any lines that don't start with
  112.   ok.b=0              ;">" or "#" and looks for one that does
  113.   Repeat
  114.     temp$=Edit$(255)
  115.     If Left$(temp$,1)=">"OR Left$(temp$,1)="#"
  116.       ret$=UnRight$(temp$,1)
  117.       ok=1
  118.     EndIf
  119.   Until ok OR Eof(0)
  120.   If ok
  121.     Function Return ret$
  122.   Else
  123.     Function Return "-1"
  124.   EndIf
  125. End Function
  126.  
  127. ;---------------------------------------------------------------
  128.  
  129. ;prints text to a bitmap using a standard intuifont
  130. ;with a dropshadow, centered horizontally on cntrx
  131.  
  132. ;modified from a code by David McMinn
  133.  
  134. Statement BPrint{a$,xcntr.w,dummy.w,y.w}
  135.  
  136.   DEFTYPE.RastPort rp
  137.  
  138.   InitRastPort_ &rp                        ;create a rastport
  139.                                            ;for our bitmap
  140.   rp\_BitMap = Addr BitMap(1)
  141.  
  142.   SetFont_ &rp,Peek.l(Addr IntuiFont(0)+8) ;tell it which font
  143.   SetDrMd_ &rp,0                           ;set jam mode 0
  144.   pixels=TextLength_(&rp,&a$,Len(a$))      ;find the pixel length
  145.   x.w=xcntr-pixels/2                       ;for centering the text
  146.   If x<10 Then x=10
  147.   Move_ &rp,x+1,y+1                        ;locate the cursor
  148.   SetAPen_ &rp,1                           ;set colour to black
  149.   Text_ &rp,&a$,Len(a$)                    ;print the text
  150.   Move_ &rp,x,y                            ;relocate the cursor
  151.   SetAPen_ &rp,7                           ;set to colour 7
  152.   Text_ &rp,&a$,Len(a$)                    ;draw foreground text
  153.  
  154. End Statement
  155.  
  156. ;----------------------------------------------------------------
  157. ; use reqtools requesters
  158. ; using the same strings as Request...
  159. ; just because I don't like sticking in all those
  160. ; CHR$(10) 's   ;)
  161.  
  162. Function.b RTreq{title$,body$,gadget$}
  163.   rq$=Replace$(body$,"|",Chr$(10))
  164.   answer.b=RTEZRequest(title$,rq$,gadget$,2,0,4)
  165.   Function Return answer
  166. End Function
  167.  
  168. ;---------------------------------------------------------
  169.  
  170. ; fade the current screen to a new palette
  171. Statement fadeto{palobj,speed}     ;speed must be >0  !!!!
  172.   PaletteInfo palobj
  173.   For i = 0 To 15                  ;number of available colour steps
  174.    For j=0 To 7                    ;number of currently used colours
  175.     rd = Red(j)
  176.     If rd < PalRed(j)  Then rd+1   ;check each for the difference
  177.     If rd > PalRed(j) Then rd-1    ;between current colour and
  178.     bl = Blue(j)                   ;the target colour
  179.     If bl < PalBlue(j)  Then bl+1  ;and reset as needed
  180.     If bl > PalBlue(j) Then bl-1
  181.     gr = Green(j)
  182.     If gr < PalGreen(j) Then gr+1
  183.     If gr > PalGreen(j) Then gr-1
  184.     RGB j,rd,gr,bl                 ;send the palette to the screen
  185.    Next j
  186.    VWait speed                     ;take this out if too slow or
  187.   Next i                           ;increase if too fast
  188. End Statement
  189. ;----------------------------------------------------------------
  190. Statement setPointer{style.b,active.b}  ;pointer,calling window
  191.   For i = 0 To Maximum Window -1
  192.     If Peek.l(Addr Window(i))      ;sets the window's pointer to the
  193.       Use Window i                 ;requested shape:
  194.       WPointer style
  195.     EndIf
  196.   Next                             ;normal      - finger points
  197.   Use Window active                ;buttondown  - finger pushing
  198. End Statement                      ;waitpointer - finger curled
  199. ;----------------------------------------------------------------
  200.  
  201. ntsSys=NTSC                        ;True if a NTSC system
  202. Forced.b=0                         ;if display was forced
  203. WbToScreen 1
  204. *SCR.Screen=Peek.l(Addr Screen(1)) ;find the WB screen structure
  205. wb.l=*SCR\Width                    ;how wide is user's screen?
  206. Free Screen 1                      ;that's all we need to know
  207. If wb>720 Then wb=720              ;check for oversized bench
  208. If wb<640 Then wb=640              ;or undersized...
  209.  
  210. wb=Int(wb/2)                       ;divide for our lo-res screen
  211. ofst.l=Int((wb - 320)/2)           ;and get horizontal to center it
  212.  
  213. .Loadup
  214. MaxLen newmod$=255                 ;for selecting new module
  215. MaxLen fi$    =255                 ;filename $
  216. MaxLen pa$    =255                 ;mod path $
  217. MaxLen snd$   =255                 ;sounds path $
  218. MaxLen newsnd$=255
  219. MaxLen cardfi$=255                 ;card file
  220. MaxLen cardpa$=255                 ;card path
  221. MaxLen locpa$ =255                 ;locale path
  222. MaxLen locfi$ =255                 ;locale file
  223. locpa$=ourpath$+"/Locale"          ;path to our locale files
  224. cardpa$="cards"                    ;path to our card pics
  225. temp$="Crazy8's"
  226. Dim txt$(90)                       ;for text from the locale files
  227. txt$(87)="Locale"                  ;default
  228. locale$=Language{}                 ;read the system locale setting
  229.  
  230. BitMap 0,320,200,3                 ;lo-res 8 colors
  231. BitMap 1,320,200,3                 ;double buffered drawing page
  232. InitPalette 0,8                    ;set a palette to all black
  233. Screen 0,ofst,0,320,200,3,0,temp$,0,0,0  ;open the screen
  234. Use Palette 0                      ;black screen to start
  235. Window 0,0,0,320,200,$1900," ",0,0 ;open our window
  236. MenusOff
  237. ShowBitMap 1                       ;show blank page
  238. CatchDosErrs                       ;show system requestors on our screen
  239. LoadBitMap 0,"data/C8.Title",0     ;load the title screen pic
  240. SetCycle 0,0,2,5,.25               ;set up for color cycling
  241. ShowBitMap 0                       ;get title screen ready
  242. Cycle 0                            ;make letters on title "squirm"
  243. fadeto{0,2}                        ;and fade in the title screen
  244. Gosub loadpref                     ;load the prefs file
  245. Gosub GetLocale                    ;now load the locale file
  246. Gosub grabcards                    ;and the card shapes
  247. hold.w=0                           ;used for message delay
  248. Use BitMap 0
  249. LoadBitMap 1,"data/C8.playscreen",1 ;load game screen & palette
  250. LoadPalette 2,"data/pal.pref"       ;load the palettes
  251. LoadPalette 3,"data/pal.x"
  252. LoadPalette 4,"data/pal.green"
  253. LoadPalette 5,"data/pal.grey"
  254. LoadPalette 6,"data/pal.tan"
  255. LoadPalette 7,"data/pal.maroon"
  256. LoadPalette 8,"data/pal.purp"
  257. LoadPalette 9,"data/pal.purp2"
  258. LoadPalette 10,"data/pal.yelo"
  259. LoadPalette pl.b,"data/pal.pointer",16 ;colors for the pointers
  260.  
  261. Dim sd$(33)                         ;for the 34 sounds
  262. Dim Timeout.w(33)                   ;and their mask time
  263. For i=0 To 33                       ;read sound names from data $
  264.   Read sd$(i)
  265. Next
  266.  
  267. ;Names for the sounds:
  268. Data$ "Laugh","aarrgghh!","awwww","NotCompute","clap"
  269. Data$ "drum","GameOver","scream","Shuffle","snare"
  270. Data$ "tankoo","uh-oh","spoit","tick","bell"
  271. Data$ "Cuckoo","Hey1","boom","Whoosh","BowArrow"
  272. Data$ "Cut.it.out","Girl.sigh","Glepuughn","Oooh","DaMeaning"
  273. Data$ "Spit","Yeah","Drip1","WhatDo","Carumba"
  274. Data$ "doh01","doh30","doh31","excellent"
  275.  
  276. Gosub LoadSounds
  277.  
  278. If Peek.l(Addr Sound(0))            ;make sure it's there!
  279.   Sound 0,1                         ;play the crazy laugh
  280.   VWait 12                          ;and echo it in
  281.   Sound 0,2                         ;the other speaker
  282. EndIf
  283.  
  284. SetErr
  285.  ShowBitMap 0                       ;make sure we're on the right bitmap
  286.  Use BitMap 0                       ;and put up a requestor
  287.  a=RTreq{txt$(60),txt$(62),txt$(61)}
  288.  StopMed
  289.  Quiet 15
  290.  End                                ;and end program
  291. End SetErr                          ;that wasn't so hard!
  292.  
  293. LoadShapes 54,59,"data/flip.shps"   ;54-57 cardflips
  294.                                     ;58 suit select/59 8 <-
  295.                                     ;60-63 s/h/c/d
  296. LoadShapes 65,"data/pointer.shps"   ;65-67, normal,btn dwn,wait pointers
  297. normal.b=65
  298. buttondown.b=66
  299. waitpointer.b=67
  300. LoadShapes 69,"data/gad.shapes"     ;- Menu buttons: 38x36 pixels
  301.                                     ;24 shapes (up + down)
  302. Use BitMap 1                        ;use the unseen page
  303. Boxf 16,110,40,142,6                ;draw a "blank" shape
  304. GetShape {68,16,110,24,32}          ;pick it up for erasing
  305. MidHandle 68                        ;and set its handle to center
  306. Boxf 16,110,40,142,0
  307. Use BitMap 0                        ;now use the title page
  308. If ModOn.b=1                        ;Load music mod if wanted
  309.   ld$=pa$+"/"+fi$                   ;make loading $
  310.   LoadMedModule 0,ld$               ;load the music
  311.   music=1                           ;set the music on flag
  312. Else                                ;if no module is to be loaded
  313.   music=0                           ;make sure the flag is off!
  314. EndIf
  315. VWait 120                           ;wait for the laugh to end
  316. Gosub MusicOn                       ;start music & set filter
  317.  
  318. DEFTYPE.RastPort rp                 ;for the bitmap printing routine
  319. InitRastPort_ &rp
  320. rp\_BitMap = Addr BitMap(1)
  321. SetFont_ &rp,Peek.l(Addr IntuiFont(0)+8)
  322.  
  323. ;======================================================================
  324.  
  325. SetInt 5                            ;countdown the timer
  326. If hold.w                           ;and play the music
  327.   hold-1
  328. EndIf
  329. If music=1                          ;only if the music is on
  330.  If hold=1 Then SetMedMask 15       ;if the sound is done, use all 4
  331.  PlayMed                            ;channels for the music
  332. End If
  333. End SetInt
  334.  
  335. ;======================================================================
  336.  
  337. .Initialize
  338. Dim Deck.b(52)    ;Deck of Cards
  339. Dim Pile.b(52)    ;Discard Pile
  340. Dim Phand.b(52)   ;Player's Hand  ( Card# )
  341. Dim Ppos.w(52,1)  ;Player Card Positions (x,y)
  342. Dim Chand.b(52,3) ;Computer's Hand (Card,playability,suit,rank)
  343. Dim scorename$(30)
  344. Dim gamesplayed(30)
  345. Dim gameswon(30)
  346. Dim winpct.w(30)
  347.  
  348. NEWTYPE.scores    ;for the listviews
  349.   pad.w
  350.   string.s
  351. End NEWTYPE
  352.  
  353. Dim List sndDrawers.scores(50)
  354.  
  355. complain.b=1        ;computer's complaints
  356. DEFTYPE.b Split     ;end game flag
  357. DEFTYPE.w Pscore    ;Player's Score
  358. DEFTYPE.w Cscore    ;Computer Score
  359. DEFTYPE.b Pcards    ;Cards in Player's Hand
  360. DEFTYPE.b Ccards    ;Cards in Computer Hand
  361. DEFTYPE.b Cspades   ;number of cards in each suit in
  362. DEFTYPE.b Chearts   ;  computer's hand
  363. DEFTYPE.b Cclubs
  364. DEFTYPE.b Cdiamonds
  365. DEFTYPE.b Cmost     ;suit computer has most of
  366. DEFTYPE.b Compeight ;how many 8's computer has
  367. DEFTYPE.b mxx       ;maximum cards of any suit
  368. DEFTYPE.b PlayCard  ;Card selected for play
  369. DEFTYPE.b Inhand    ;Position in player's hand
  370. DEFTYPE.b Suit      ;Suit of selected card
  371. DEFTYPE.b Rank      ;Rank of card selected (A - K)
  372. DEFTYPE.b CSuit     ;Current suit (s/h/c/d)
  373. DEFTYPE.b CRank     ;Current rank of card (A - K)
  374. Dcards.b=52         ;Cards left in the deck
  375. DEFTYPE.b Dpile     ;Cards in discard pile
  376. DEFTYPE.b card      ;Current Card
  377. DEFTYPE.w sx        ;shape drawing x
  378. DEFTYPE.w sy        ;shape drawing y
  379. cx.w=16             ;comp. card x
  380. cy.w=40             ;comp. card y
  381. DEFTYPE.w dx        ;destination x
  382. DEFTYPE.w dy        ;destination y
  383. DEFTYPE.b sortflag  ;is player's hand sorted?
  384. DEFTYPE.w rd        ;colors for fading
  385. DEFTYPE.w bl
  386. DEFTYPE.w gr
  387. DEFTYPE.b flip      ;for turning cards over
  388. DEFTYPE.b flipfrom
  389. DEFTYPE.b flipto
  390. up.b=1
  391. down.b=-1
  392. DEFTYPE.b comppull  ;number of cards computer picked up
  393. DEFTYPE.b compflag  ;is it computer's turn?
  394. DEFTYPE.b playerflag;is it player's turn?
  395. DEFTYPE.b pickup    ;number of cards player picked up
  396. DEFTYPE.b see       ;bitmap being viewed
  397. DEFTYPE.b draw      ;bitmap being drawn on
  398. DEFTYPE.b temp      ;temporary storage
  399. DEFTYPE.b temp2
  400. DEFTYPE.b temp3
  401. DEFTYPE.w paltemp
  402. DEFTYPE.b ok        ;is this card ok to play?
  403. DEFTYPE.b shp       ;shape # to be drawn
  404. DEFTYPE.b btn       ;1=left  2=right mouse button clicked
  405. DEFTYPE.w mx        ;mouse x position
  406. DEFTYPE.w my        ;mouse y position
  407. DEFTYPE.w chx       ;check x
  408. DEFTYPE.w chy       ;check y
  409. DEFTYPE.b hit       ;item that was clicked on
  410. DEFTYPE.b check     ;item being checked
  411. Row.b=1             ;Row selected card is in
  412. Rowflag.b=1         ;Number of rows in players hand
  413. DEFTYPE.b setup     ;1 if game was already played
  414. DEFTYPE.b replay
  415. DEFTYPE.b sleep     ;program is sleeping but start music if = 1 on return
  416. defpa$="data/mods"      ;default path for music module
  417. deffi$="med.moonshine"  ;default mod name
  418. zap$=Chr$(133)+" "+Chr$(134)
  419.  
  420. Buffer 0,8192     ;set up the drawing buffers
  421. Buffer 1,8192     ;for each drawing page
  422. For i = 1 To 52   ;set up the "deck" of cards
  423.   Deck(i)=i
  424. Next
  425.   px.w=15         ;preset the positions for
  426.   py.w=128        ;all 50 cards to go
  427. For i = 1 To 50   ;in the player's hand
  428.   If i=26         ;in two horizontal
  429.     px=15         ;rows
  430.     py=162
  431.   EndIf
  432.   Ppos(i,0)=px    ;and store them in
  433.   Ppos(i,1)=py    ;an array
  434.   px+12
  435. Next
  436.  
  437. .MakeMenu         ;gadgetlist for the Menu Button Window
  438.  
  439. For i = 69 To 92
  440.   Handle i,0,0
  441. Next
  442.  
  443. ShapeGadget 0,  0, 0,0,1,69,70    ;Play
  444. ShapeGadget 0, 38, 0,0,2,71,72    ;Score
  445. ShapeGadget 0, 76, 0,0,3,73,74    ;Palette
  446. ShapeGadget 0,114, 0,0,4,75,76    ;Sounds
  447. ShapeGadget 0,152, 0,0,5,77,78    ;Music
  448. ShapeGadget 0,190, 0,0,6,79,80    ;Exit
  449.  
  450. ShapeGadget 0,  0,35,0,7,81,82    ;Save Prefs
  451. ShapeGadget 0, 38,35,0,8,83,84    ;Locale
  452. ShapeGadget 0, 76,35,0,9,85,86    ;Game Setup
  453. ShapeGadget 0,114,35,0,10,87,88   ;Cards
  454. ShapeGadget 0,152,35,0,11,89,90   ;Screen
  455. ShapeGadget 0,190,35,0,12,91,92   ;Load Prefs
  456.  
  457. draw=1                       ;draw on page one
  458. StopCycle                    ;stop the title from flashing
  459. Use Palette pl.b             ;and reset the palette
  460. For i = 0 To 7               ;set palette 0 to all black again
  461.   PalRGB 0,i,0,0,0           ;for the fade-outs
  462. Next
  463. fadeto{0,1}
  464. ShowBitMap 1
  465. CopyBitMap 1,0
  466.  
  467. fadeto{pl,1}
  468. setPointer{normal,0}         ;show the normal game pointer
  469.  
  470. .StartScreen
  471. gamedone.b=0
  472. prefok.b=1
  473. Gosub MenU                   ;see what they want to do
  474. prefok=0
  475.  
  476. .Playgame                    ;finally, we can play the game!
  477. setPointer{waitpointer,0}  ;show wait pointer
  478. replay=0
  479. Format "###"
  480. a$=txt$(4)+" "+Str$(maxpoints.w)
  481.  
  482. Use BitMap 1                 ;make sure we are using the unseen page
  483.  
  484. Boxf 108,62,210,72,3         ;Erase any old text first
  485. Boxf 108,73,176,99,3         ;and any old names
  486.  
  487. BPrint{a$,160,0,69}          ;Playing To xxx
  488. BPrint{compname$,140,0,83}   ;Computer name
  489. BPrint{playername$,140,0,94} ;Player name
  490. Blit 0,232,82                ;the deck
  491. Gosub Newpage                ;switch pages
  492. CopyBitMap see,draw          ;and make both pages look the same
  493. fadeto{pl,1}                 ;and fade in the screen
  494. If setup=0                   ;this is the very first game
  495.   noise=12:Gosub makenoise   ;so make a noise!
  496.   VWait 30
  497. EndIf
  498. FlushEvents
  499.  
  500. .Newhand                     ;set up for a new hand
  501. Gosub showscore              ;update the score
  502. Gosub showCcards
  503. If setup=1                   ;if it's not the first game
  504.   Message$=txt$(5)
  505.   showtrans.b=0
  506. Else
  507.   If trans1$<>"Curt Esser"   ;my name is already shown
  508.     If trans2$<>"..."        ;anyway - no need to show
  509.       showtrans.b=2          ;it twice
  510.     Else
  511.       showtrans=1
  512.     EndIf
  513.   EndIf
  514. EndIf
  515.  
  516. Dcards=52:Pcards=0:Ccards=0:Dpile=0:compflag=0:playerflag=0
  517.  
  518. For i=1 To 52                ;set up a new deck of cards
  519.  Deck(i)=i                   ;in order to start with
  520. Next
  521.  
  522. Gosub Shuffle                ;and shuffle them
  523. If showtrans                 ;on the first hand, we show
  524.   Message$=transby$          ;the translator's name(s)
  525.   Gosub PrintMessage
  526. EndIf
  527.  
  528. For d=1 To 5                 ;deal 5 cards to each player
  529.   Gosub Compget              ;one to each
  530.   Gosub showCcards
  531.   Gosub Playerget            ;in order
  532.   If d=1 AND showtrans
  533.     Message$=trans1$         ;and put up the first translator
  534.     Gosub PrintMessage
  535.   EndIf                      ;then the 2nd, if there is one
  536.   If d=3 AND showtrans=2
  537.     Message$=locand$+" "+trans2$
  538.     Gosub PrintMessage
  539.   EndIf
  540. Next
  541. setup=1
  542.  
  543. Upcard                       ;turn next card up to start game
  544. Gosub Grabcard               ;get the card
  545. Repeat
  546.    sx-4                      ;and slide it over
  547.    Gosub Draw
  548. Until sx=88                  ;into position
  549. flip=up
  550. Gosub Flipit                 ;now flip it over
  551. Dpile+1                      ;and keep track of what's
  552. Pile(Dpile)=card             ;in the pile
  553. Gosub WhatCard               ;now convert it from a number
  554. CSuit=Suit                   ;to the Current Suit
  555. CRank=Rank                   ;and Current Rank
  556. Gosub Sorthand               ;sort the player's hand
  557. If music=1
  558.   Gosub MusicOn              ;and start the music if it's on
  559. EndIf
  560. VWait
  561. noise=27                     ;let user know
  562. Gosub makenoise              ;we're ready to play
  563.  
  564. ;-------------------------------------------------------------------
  565. ;                         MAIN GAME LOOP
  566. ;-------------------------------------------------------------------
  567.  
  568. .GameLoop
  569. pickup=0            ;nothing has been picked up yet!
  570. Message$=txt$(6)+pgreet$
  571. If Ccards=1 Then Message$=txt$(7)
  572. Gosub PrintMessage
  573.  
  574. .PlayerTurn
  575. playerflag=1        ;human's turn
  576. ok=0
  577. Gosub getmouse      ;wait for input
  578. CopyBitMap see,draw ;make sure both pages are the same
  579. ShowBitMap 0
  580. Use BitMap 1
  581. see=0
  582. draw=1
  583.  
  584. If hit=0
  585.   Gosub HitWhat     ;OK, what happened?
  586. EndIf
  587.  
  588. Select hit          ;now deal with the selection
  589.   Case 1            ;clicked deck
  590.     Gosub Playerget ;pick up a card from the deck
  591.     pickup+1        ;count how many cards are picked up this turn
  592.   Case 2            ;player clicked MENU
  593.     Gosub MenU      ;so deal with it
  594.   Case 3            ;player clicked a card
  595.     card=PlayCard   ;ok we'll try to play it
  596.     Gosub WhatCard  ;check if it's a legal play
  597.       If ok=1       ;it is so let user play it
  598.  
  599.         If card=Phand(Pcards)  ;this card was just picked up
  600.           pickup-1             ;so take it off the count
  601.         EndIf                  ;and maybe we won't need to sort hand
  602.         noise=5:Gosub makenoise
  603.         Gosub Pullcard                    ;pull it out
  604.         Gosub Playcard                    ;and play it
  605.         noise=13:Gosub makenoise
  606.         If Row<>Rowflag
  607.           Gosub MoveUp         ;if two rows move one card up
  608.         EndIf
  609.         For i=Inhand To Pcards ;this stuff moves the cards
  610.           Phand(i)=Phand(i+1)  ;over to correct the array
  611.           Next                 ;for the card we took out
  612.         Pcards-1:playerflag=0  ;and correct the count
  613.         If CRank=8
  614.           Gosub SetSuit        ;choose suit if an 8 played
  615.         EndIf
  616.       Else                     ;go here if the card
  617.         noise=3                ;is not a legal play
  618.         Gosub makenoise        ;let the user know about it
  619.       EndIf                    ;and do nothing else
  620.   Case 4                       ;clicked SORT
  621.     If Pcards=1 OR Sortflag=1  ;no need to sort
  622.       noise=16                 ;so we'll make
  623.       Gosub makenoise          ;a sound instead
  624.       VWait 10                 ;in fact, let's make
  625.       Gosub makenoise          ;it echo too!
  626.     Else
  627.       Gosub Sorthand           ;ok, we'll sort the hand
  628.     EndIf
  629.   Case 5                       ;player clicked hide
  630.     sleep=2                    ;so set the sleep flag
  631.     Message$=c8$
  632.     Gosub PrintMessage
  633.     If music=1
  634.       sleep=1                  ;make it 1 to restart music later
  635.       music=0                  ;but turn it off now
  636.       playing.b=0
  637.       StopMed
  638.     End If
  639.     VWait 2
  640.     Gosub Drawdone
  641.     If Forced>0
  642.       Gosub FixMode
  643.     EndIf
  644.     WBenchToFront_             ;and bring up WorkBench
  645.     dummy=SetMouse{wb*2,80,1}
  646.     dummy=SetMouse{wb,80,0}    ;and activate it by clicking
  647.   Default                      ;player has clicked something else
  648.     noise=3                    ;but there IS nothing else!
  649.     Gosub makenoise            ;let 'em know they made a mistake
  650. End Select
  651. hit=0
  652. If sleep>0
  653.   FlushEvents
  654.   Goto PlayerTurn              ;wait for 'em to come back
  655. EndIf
  656. VWait
  657. If Split=1 Then Goto split     ;user wants to quit so do it
  658. If Pcards=0                    ;player has won hand!
  659.    playerflag=1                ;so set the flag
  660.    Goto Handover               ;and end this hand
  661. EndIf
  662. If Dcards=0
  663.   Gosub Reshuffle              ;no cards left - use discards
  664. EndIf
  665. If playerflag=1
  666.   Goto PlayerTurn              ;it's still the player's turn
  667. EndIf
  668. If Sortflag=0 AND pickup>0
  669.   Gosub Sorthand               ;sort the cards if necessary
  670. EndIf
  671.  
  672. holdit.b=2                     ;computer's turn now
  673. Message$=txt$(8)               ;so greet the player
  674. setPointer{waitpointer,0}      ;and put up wait pointer
  675. comppull=0                     ;and reset pickup count
  676. If Pcards=2 AND Ccards>2       ;player only has 2 cards
  677.   Gosub CompNoise              ;and we have more so we complain
  678.   Message$=txt$(complain+8)    ;set a new complaint
  679.   Gosub CompComplain
  680. EndIf
  681.  
  682. If Pcards=1                    ;now the player only has one card
  683.   Gosub CompNoise
  684.   Select complain              ;so REALLY whine about it
  685.     Case 1
  686.       Message$=txt$(18)
  687.       noise=20
  688.     Case 8
  689.       Message$=txt$(25)
  690.       noise=22
  691.     Default
  692.       Message$=txt$(complain+17)
  693.   End Select
  694.   Gosub CompComplain
  695. EndIf
  696. WildHair.b=0
  697. If CRank=8 AND Pcards=1 AND Rnd(10)>4
  698.   WildHair=1
  699.   pullet.b=Rnd(8)+6
  700. EndIf
  701. .Computerturn
  702.    ; Chand.b(52,3) ;Computer's Hand (Card,playability,suit,rank)
  703.  
  704. Gosub PrintMessage     ;let 'em know it's our turn now
  705. Gosub FinishSound
  706. ok=0:cplay.b=0:compflag=1:Cspades=0:Chearts=0:Cclubs=0
  707. Cdiamonds=0            ;reset everything for this turn
  708. For i=1 To Ccards
  709.   card=Chand(i,0)                         ;this part checks
  710.   Gosub WhatCard                          ;the computer's hand
  711.   If Suit=0 AND Rank<>8 Then Cspades+1    ;for the number of
  712.   If Suit=1 AND Rank<>8 Then Chearts+1    ;cards of each suit
  713.   If Suit=2 AND Rank<>8 Then Cclubs+1     ;so we know what suit to
  714.   If Suit=3 AND Rank<>8 Then Cdiamonds+1  ;pick if we play an 8
  715.  
  716.   mxx=Cspades:Cmost=0             ;this stuff
  717.   If Ccards=1                     ;finds out which suit we have
  718.     mxx=1                         ;the most of so we can pick it
  719.     If Chearts=1 Then Cmost=1     ;if we played an 8
  720.     If Cclubs=1 Then Cmost=2      ;if 2 or more are equal, we'll
  721.     If Cdiamonds=1 Then Cmost=3   ;randomly pick one of them
  722.   Else
  723.     If Chearts>mxx OR (Chearts=mxx AND Rnd(2)>1)
  724.       Cmost=1
  725.       mxx=Chearts
  726.     EndIf
  727.     If Cclubs>mxx OR (Cclubs=mxx AND Rnd(2)>1)
  728.       Cmost=2
  729.       mxx=Cclubs
  730.     EndIf
  731.     If Cdiamonds>mxx OR (Cdiamonds=mxx AND Rnd(2)>1)
  732.       Cmost=3
  733.     EndIf
  734.   EndIf
  735.  
  736.   Chand(i,1)=0                   ;not playable
  737.   Chand(i,2)=Suit
  738.   Chand(i,3)=Rank
  739.   If ok=1
  740.     If Rank<>8                   ;if the card is a legal play
  741.       Chand(i,1)=1
  742.     Else
  743.       Chand(i,1)=-1              ;8 flag
  744.     EndIf
  745.   EndIf
  746.  ;If ok=1 AND (Pcards>1 OR Ccards=1 OR Rank=CRank) Then Chand(i,1)=1 ;card is a legal play
  747. Next
  748. For i = 1 To Ccards              ;OK, now score play desirability
  749.   If Chand(i,1)>0                ;only on playable cards, of course!
  750.     If Chand(i,2)=Cmost
  751.       Chand(i,1)+1               ;have most of this suit!
  752.     EndIf
  753.     For j = 1 To Ccards
  754.       If j<>i AND Chand(j,1)<>-1
  755.         If Chand(i,3)=Chand(j,3) ;same Rank as another card in our hand!
  756.           Chand(i,1)+1
  757.         EndIf
  758.       EndIf
  759.     Next
  760.   EndIf
  761. Next
  762. Compeight=0
  763. Best.b=1                         ;pick the best card to play
  764. For i=1 To Ccards
  765.   If Chand(i,1)=>Best
  766.     Best=Chand(i,1)
  767.     cplay=i                      ;ok, we will play this one
  768.   EndIf
  769.   If Chand(i,1)=-1
  770.     Compeight+1
  771.   EndIf
  772. Next
  773. If WildHair AND comppull<pullet
  774.   cplay=0                          ;try for an 8 to block a win
  775. EndIf
  776. If (cplay=0 AND (Ccards<Compeight*2+1 OR Pcards<=Compeight OR Pcards=1)) OR Dcards<2 OR Ccards=Compeight ;OR Pcards<(Ccards/2
  777.   For i=1 To Ccards                ;no non-8's to play
  778.     If Chand(i,1)=-1 Then cplay=i  ;so play an 8 if we have one
  779.   Next                             ;unless we're way ahead
  780. EndIf                              ;we'll save the 8 and draw
  781. If Pcards>4 AND Ccards>2 AND cplay
  782.   If Rnd(30) > 28 Then cplay=0     ;just a bit of randomness to throw 'em off
  783. EndIf
  784. If cplay>0                         ;we're going to play a card
  785.   If comppull=0 AND Ccards=1       ;if it's our last card
  786.     noise=10:Gosub makenoise       ;let 'em know
  787.     Gosub FinishSound
  788.   EndIf
  789.   Gosub CompPlay                   ;play it!
  790.  
  791.   Gosub Playcard                   ;alright, play it already!
  792.   If Rank=8
  793.     Gosub SetSuit                  ;ok an 8! Set our suit!
  794.   EndIf
  795.   If Ccards=1                      ;we only have one card
  796.     noise=11                       ;left so warn the player
  797.     Gosub makenoise
  798.   End If
  799. EndIf
  800.  
  801. If cplay=0                         ;we're picking up too
  802.   If comppull>1                    ;many un-playable cards
  803.     Gosub CompNoise
  804.     Message$=txt$(complain+26)     ;so moan about it!
  805.     Gosub CompComplain
  806.     Gosub PrintMessage
  807.   EndIf
  808.   VWait hold+15
  809.   Gosub Compget                    ;go get another card
  810.   comppull+1
  811. EndIf
  812. If Dcards=0                        ;and re-shuffle the discards
  813.  Gosub Reshuffle                   ;if the deck is all used up
  814.  VWait 30
  815. EndIf
  816. Gosub showCcards
  817. If cplay=0 AND Dcards>0
  818.   Goto Computerturn                ;it's still the Amiga's turn
  819. EndIf
  820. If Ccards=0
  821.   Goto Handover                    ;Hey! we won this hand
  822. EndIf
  823. compflag=0                         ;we didn't win
  824. Goto GameLoop                      ;so back to the player
  825.  
  826. .Handover                          ;ok, we managed to finish a hand
  827. setPointer{waitpointer,0}          ;put up the busy pointer
  828. Gosub fademusic                    ;and can the music
  829. If playerflag=0                    ;the computer won
  830.   noise=2                          ;so make an appropriate noise
  831.   Gosub makenoise
  832.   Message$=txt$(36)                ;and print a message
  833.   Gosub PrintMessage
  834.   Gosub FinishSound
  835.  
  836.   Repeat
  837.     Inhand=Pcards
  838.     card=Phand(Inhand)             ;now get the player's cards
  839.     Gosub Pullcard                 ;one at a time
  840.     Gosub Playcard                 ;& put 'em on discard pile
  841.     Gosub Score                    ;and score them
  842.     Pcards-1
  843.   Until Pcards=0                   ;till we got 'em all
  844. Else                               ;player won
  845.   Message$=txt$(37)                ;say it in print
  846.   noise=0                          ;and make a noise
  847.   Gosub makenoise                  ;now print the message
  848.   Gosub PrintMessage               ;pause for a bit
  849.   Gosub FinishSound
  850.   Repeat                           ;now throw computer's cards
  851.     cplay=Ccards                   ;on the discard pile
  852.     Gosub CompPlay                 ;one at a time
  853.     Gosub Playcard
  854.     Gosub showCcards
  855.     Gosub Score                    ;and score each one
  856.   Until Ccards=0                   ;till they're all gone
  857. EndIf
  858. VWait 50
  859. flip=down
  860. Gosub Flipit            ;turn the deck face down
  861. VWait 20
  862. For i=1 To 2            ;now erase the deck
  863.   Use BitMap draw       ;off both screens
  864.   BlitMode EraseMode
  865.   Blit 68,sx,sy         ;by drawing a blank card
  866.   BlitMode CookieMode
  867.   shp=0                 ;but buffer-blit
  868.   Gosub Draw            ;the card-back pic on both pages
  869. Next                    ;so we can move it
  870. noise=18
  871. Gosub makenoise
  872. Repeat                  ;now slide the discard pile back onto
  873.   sx+4                  ;the main deck 4 pixels at a time
  874.   Gosub Draw
  875. Until sx=232
  876. Gosub Drawdone          ;reset everything for the next time
  877.  
  878. If Cscore=>maxpoints OR Pscore=>maxpoints  ;The game is over!
  879.   gamedone.b=True
  880.   noise=6
  881.   Gosub makenoise
  882.   If (Cscore=>maxpoints AND scoreon.b =0) OR (scoreon=1 AND Pscore =>maxpoints)
  883.  
  884.     Message$=txt$(38)   ;player won the game message
  885.     pwon.b=True
  886.     cwon.b=False
  887.   Else
  888.     Message$=txt$(39)   ;computer won so print this one
  889.     pwon=False
  890.     cwon=True
  891.   EndIf
  892.   Gosub PrintMessage
  893.   Cscore=0              ;reset scores
  894.   Pscore=0
  895.   Gosub FinishSound
  896.   see=0
  897.   draw=1
  898.   ShowBitMap 0
  899.   Use BitMap 0
  900.   Gosub ScoreTable
  901.   replay=1              ;set the replay flag
  902.   Goto StartScreen      ;and go back to the beginning
  903. EndIf
  904. Goto Newhand            ;game's not over, play another hand
  905.  
  906.  
  907. .MenU                   ; the button menu
  908.   Gosub Drawdone        ;make sure we're showing the Screen's bitmap
  909.   CacheClearU_
  910.   Gosub openMenu
  911.   selection.b=0
  912.   tpl=pl
  913.   Repeat
  914.     ev.l=WaitEvent
  915.     If ev=$8
  916.       Select MButtons
  917.         Case 1
  918.           setPointer{buttondown,1}
  919.         Case 2
  920.           setPointer{buttondown,1}
  921.           ClickButton 0
  922.         Case 5
  923.           setPointer{normal,1}
  924.         Case 6
  925.           setPointer{normal,1}
  926.       End Select
  927.     EndIf
  928.  
  929.     If EventWindow=1
  930.       If ev = $20
  931.          setPointer{buttondown,1}
  932.          FlushEvents $8
  933.          noise=13
  934.          Gosub makenoise
  935.       ;Else
  936.       ;   WPointer normal
  937.       EndIf
  938.       If ev=$40
  939.         setPointer{normal,1}
  940.         FlushEvents $8
  941.         Select GadgetHit
  942.           Case 1               ;Play
  943.             selection=1
  944.             noise = 33
  945.             Gosub makenoise
  946.             Gosub FinishSound
  947.  
  948.           Case 2               ;Show Score Table
  949.             noise=30
  950.             Gosub makenoise
  951.             Gosub ScoreTable
  952.  
  953.           Case 3               ;Change Palette
  954.             noise=13
  955.             Gosub makenoise
  956.             pl+1
  957.             If pl=2 OR pl=3 Then pl=4
  958.             If pl>10 Then pl=1
  959.             fadeto{pl,2}
  960.           Case 4               ;Sounds
  961.             noise=24
  962.             Gosub makenoise
  963.             Gosub getSoundPath
  964.             If newsnd$<>snd$ AND newsnd$<>""
  965.               snd$=newsnd$
  966.               showerr.b=True
  967.               Message$=txt$(75)+" "+txt$(76)
  968.               Gosub PrintMessage
  969.               setPointer{waitpointer,1}
  970.               Gosub LoadSounds
  971.               Message$=txt$(1)
  972.               Gosub PrintMessage
  973.               setPointer{normal,1}
  974.             EndIf
  975.  
  976.           Case 5               ;Music
  977.             noise=29
  978.             Gosub makenoise
  979.             Gosub LoadMed
  980.  
  981.           Case 6               ;quit
  982.             setPointer{waitpointer,1}
  983.             Gosub split
  984.  
  985.           Case 7               ;about
  986.             Message$=txt$(0)
  987.             Gosub PrintMessage
  988.             rq$=about$+"|"+locby$
  989.             dummy = RTreq{c8$,rq$,yes$}
  990.             Message$=txt$(1)
  991.             Gosub PrintMessage
  992.  
  993.           Case 8               ;load settings
  994.             Gosub getPref
  995.             If pref$<>""
  996.               prefload.b=1
  997.               newloc.b=0
  998.               setPointer{waitpointer,1}
  999.               Message$=zap$
  1000.               Gosub PrintMessage
  1001.               Gosub loadpref
  1002.               fadeto{pl,2}
  1003.               If LCase$(newloc$)<>LCase$(locale$)
  1004.                 locale$=newloc$
  1005.                 newloc=1
  1006.                 Gosub GetLocale
  1007.               EndIf
  1008.               If newloc
  1009.                 Message$=transby$
  1010.               Else
  1011.                 Message$=txt$(75)+" "+pref$
  1012.               EndIf
  1013.               Gosub PrintMessage
  1014.               If ModOn.b=1     ;load the module
  1015.                 newmod$=mmd$
  1016.                 Gosub CheckMed
  1017.               Else
  1018.                 If newloc Then VWait 280
  1019.               EndIf
  1020.               If newloc
  1021.                 Message$=trans1$
  1022.                 Gosub PrintMessage
  1023.               EndIf
  1024.               If Exists (snd$)
  1025.                 showerr.b=True
  1026.                 Gosub LoadSounds
  1027.               EndIf
  1028.               ResetTimer
  1029.               If newloc AND trans2$<>"..."
  1030.                 ResetTimer
  1031.                 Repeat
  1032.                 Until Ticks>280
  1033.                 Message$=locand$+" "+trans2$
  1034.                 Gosub PrintMessage
  1035.               EndIf
  1036.               Gosub grabcards
  1037.               If newloc
  1038.                 Repeat
  1039.                 Until Ticks>480
  1040.               EndIf
  1041.               CopyBitMap 0,1
  1042.               setPointer{normal,1}
  1043.               prefload=0
  1044.               Gosub openMenu
  1045.             EndIf
  1046.  
  1047.           Case 9
  1048.             Free Window 1
  1049.             Gosub Prefs        ;game setup
  1050.             Gosub openMenu
  1051.  
  1052.           Case 10              ;select cards
  1053.             Free Window 1
  1054.             Gosub newcards
  1055.             ;Use Window 3
  1056.  
  1057.           Case 11              ;screen
  1058.             If Forced
  1059.               If Forced=1
  1060.                 ForcePAL
  1061.                 Forced=2
  1062.               Else
  1063.                 ForceNTSC
  1064.                 Forced=1
  1065.               EndIf
  1066.             Else
  1067.               If ntsSys
  1068.                 ForcePAL
  1069.                 Forced=2
  1070.               Else
  1071.                 ForceNTSC
  1072.                 Forced=1
  1073.               EndIf
  1074.             EndIf
  1075.           Case 12              ;save prefs
  1076.             FlushEvents
  1077.             setPointer{waitpointer,1}
  1078.             Gosub savepref
  1079.             VWait 150
  1080.             Message$=txt$(1)
  1081.             Gosub PrintMessage
  1082.             setPointer{normal,1}
  1083.  
  1084.         End Select
  1085.       EndIf
  1086.     EndIf
  1087.   Until selection
  1088.   FlushEvents
  1089.   Use Window 0
  1090.   Free Window 1
  1091.   setPointer{normal,0}
  1092.   FlushEvents
  1093.   Use BitMap draw            ;go back to unseen page to draw
  1094.   If setup=1
  1095.     If gamedone=True
  1096.       Message$=zap$
  1097.     Else
  1098.       Message$=txt$(2)
  1099.     EndIf
  1100.   Else
  1101.     Message$=Chr$(133)+" "+txt$(78)+" Curt Esser "+Chr$(134)
  1102.   EndIf
  1103.   Gosub PrintMessage
  1104. Return
  1105.  
  1106. .openMenu
  1107.   noise=28
  1108.   Gosub makenoise
  1109.   Message$=txt$(1)
  1110.   Gosub PrintMessage
  1111.   Window 1,46,110,228,72,$1000|$800,"",1,0,0
  1112.   Menus Off
  1113.   setPointer{normal,1}
  1114.  
  1115.   If prefok                    ;game scoring options can
  1116.     Enable 0,8                 ;only be changed
  1117.     Enable 0,9                 ;or loaded between games!
  1118.   Else
  1119.     Disable 0,8
  1120.     Disable 0,9
  1121.   EndIf
  1122.   Redraw 1,8
  1123.   Redraw 1,9
  1124.  
  1125. Return
  1126.  
  1127. .split                       ;EXIT GAME
  1128.   Message$=txt$(3)
  1129.   If setup=1 Then Gosub PrintMessage
  1130.   noise=6:Gosub makenoise
  1131.   Gosub FinishSound
  1132.   Gosub fademusic            ;turn music off
  1133.   Free MedModule 0           ;and release the mod's memory
  1134.  
  1135. split2
  1136.  
  1137.   noise=19:Gosub makenoise
  1138.   fadeto{0,3}                ;fade to black
  1139.  
  1140.   noise=17:Gosub makenoise   ;a last audio "shot"
  1141.   If Forced >0               ;fix screenmode if it was forced
  1142.     Gosub FixMode
  1143.   EndIf
  1144.   ex$="Assign Fonts: Crazy:fonts/ REMOVE"
  1145.   Execute_ ex$,0,0
  1146.   ex$="Assign Crazy: REMOVE"
  1147.   Execute_ ex$,0,0
  1148.   Gosub FinishSound
  1149.   Quiet 15                   ;can the sound channels
  1150.   End                        ;We're history
  1151. Return
  1152.  
  1153. .Draw                   ;DOUBLE BUFFERED DRAWING ROUTINE
  1154.   ShowBitMap see        ;show the already-drawn page
  1155.   VWait                 ;wait for the Vblank
  1156.   Use BitMap draw       ;now draw on the unseen page
  1157.   UnBuffer draw         ;erase the stuff we drew last time
  1158.   BBlit draw,shp,sx,sy  ;buffer-blit specified shape
  1159.   Exchange see,draw     ;make this the new viewing page
  1160. Return
  1161.  
  1162. Drawdone                ;this part simply
  1163.   ShowBitMap see        ;resets both drawing pages
  1164.   VWait                 ;so they are the same
  1165.   CopyBitMap see,draw   ;and clears out both buffers
  1166.   FlushBuffer 0         ;so we are ready for the next
  1167.   FlushBuffer 1         ;animation
  1168.   ShowBitMap 0
  1169.   see=0
  1170.   draw=1
  1171.   Use BitMap draw
  1172. Return
  1173.  
  1174. Newpage                 ;this routine switches the
  1175.   Exchange see,draw     ;drawing (unseen) and
  1176.   ShowBitMap see        ;the veiwing (seen) pages
  1177.   VWait                 ;so we don't have to do it
  1178.   Use BitMap draw       ;by hand all the time
  1179. Return
  1180.  
  1181. .Flipit                 ;ANIMATION OF CARD TURNING OVER
  1182.   flipfrom=54
  1183.   flipto=57             ;flip shapes from face down to face up
  1184.   If flip=down
  1185.     Exchange flipfrom,flipto  ;do in reverse if needed
  1186.   EndIf
  1187.   For i=flipfrom To flipto Step flip  ;draw the shapes one
  1188.     shp=i                             ;per frame till they
  1189.     Gosub Draw                        ;are all done
  1190.     VWait
  1191.   Next
  1192.   shp=card                            ;then draw actual card
  1193.   If flip=down Then shp=0             ;or card back
  1194.   Gosub Draw
  1195.   noise=13
  1196.   Gosub makenoise
  1197.   Gosub Drawdone
  1198. Return
  1199.  
  1200. .Reshuffle                 ; RESHUFFLE THE DISCARD PILE
  1201.   If Dpile=1 Then Return   ; there's only one card - forget it!
  1202.   For i=1 To Dpile-1       ; leave the top card out
  1203.     Deck(i)=Pile(i)        ; and set up our new deck using
  1204.   Next                     ; the rest of the discards
  1205.   sx=88:sy=82              ; now we slide the top card over
  1206.   If CRank=8
  1207.     shp=60+CSuit
  1208.   Else
  1209.     shp=Pile(Dpile)
  1210.   EndIf
  1211.   Use BitMap draw
  1212.   For i=1 To 2
  1213.     Blit Pile(Dpile-1),sx,sy  ;first we have to draw
  1214.     BBlit draw,shp,sx,sy      ;the next card down in the pile
  1215.     Gosub Newpage             ;on both pages under the top card
  1216.   Next                        ;because it will be seen soon
  1217.   For i=1 To 12               ;now we slide the top card
  1218.     sx-2                      ;over to the left
  1219.     Gosub Draw
  1220.   Next
  1221.   Gosub Drawdone
  1222.   sx=88:sy=82:flip=down:
  1223.   Gosub Flipit                ;now flip the "deck" over
  1224.   For i=1 To 2                ;now we need to erase
  1225.     BlitMode EraseMode
  1226.     Blit 68,sx,sy             ;both pages under the
  1227.     BlitMode CookieMode
  1228.     BBlit draw,shp,sx,sy      ;"deck" pic
  1229.     Gosub Newpage             ;actually just 1 card back pic
  1230.   Next
  1231.   Repeat                      ;now we slide this over to the right
  1232.     sx+6
  1233.     Gosub Draw
  1234.   Until sx=232                ;until it gets to the deck position
  1235.   Gosub Drawdone
  1236.   sx=64
  1237.   If CRank=8
  1238.     shp=60+CSuit
  1239.   Else
  1240.     shp=Pile(Dpile)
  1241.   EndIf
  1242.                               ;now slide the top card back
  1243.   BlitMode EraseMode
  1244.   Blit 68,sx,sy               ;where it was
  1245.   BlitMode CookieMode
  1246.   For i=1 To 2
  1247.     BlitMode EraseMode
  1248.     Blit 68,sx,sy
  1249.     BlitMode CookieMode
  1250.     BBlit draw,shp,sx,sy
  1251.     Gosub Newpage
  1252.   Next
  1253.   For i=1 To 12
  1254.     sx+2
  1255.     Gosub Draw
  1256.   Next
  1257.   Gosub Drawdone
  1258.  
  1259.   Dcards=Dpile-1              ;now reset
  1260.   Pile(1)=Pile(Dpile)         ;the discard pile
  1261.   Dpile=1
  1262.  
  1263. .Shuffle                      ;shuffle the deck
  1264.   If Dcards=1 Then Return     ;only one card - forget it!
  1265.   temp$=Message$
  1266.   If setup Then Message$=zap$
  1267.   Gosub PrintMessage
  1268.   setPointer {waitpointer,0}  ;busy pointer
  1269.   Blit 0,230,82               ;draw two card backs
  1270.   Blit 0,234,82               ;offset from normal position
  1271.                               ;but only on one page for animation
  1272.   For j=1 To 6                ;shuffle them 6 times
  1273.     For i=1 To Dcards                       ;re-arrainge deck
  1274.       Exchange Deck(i),Deck(Rnd(Dcards)+1)  ;at random by exchanging
  1275.     Next                                    ;card numbers
  1276.     noise=8               ;now make shuffling
  1277.     Gosub makenoise       ;sound and
  1278.     For i=1 To 20         ;animate by fliping the pages
  1279.       ShowBitMap draw     ;back and forth enough times
  1280.       VWait               ;to cover the length of the sound
  1281.       ShowBitMap see
  1282.       VWait               ;the actual shuffling takes no time at all
  1283.     Next                  ;this is all for show!
  1284.   Next
  1285.   Gosub Drawdone
  1286.   If setup
  1287.     Message$=temp$
  1288.     Gosub PrintMessage
  1289.   EndIf
  1290. Return
  1291.  
  1292. Grabcard                 ;pick up the top card on the deck
  1293.   If Dcards<1            ;wait a minute! There's no more cards!
  1294.     card=-1              ;so set the flag
  1295.     Return               ;and leave
  1296.   EndIf
  1297.   card=Deck(Dcards)      ;always take the top card
  1298.   Dcards-1               ;and subtract one from the deck count
  1299.   sx=232                 ;set the starting position
  1300.   sy=82                  ;for the animation
  1301.   shp=0                  ;and set to card-back shape
  1302.   If Dcards=0            ;and if this is the last card
  1303.     Use BitMap draw      ;erase the deck pic
  1304.     For i=1 To 2         ;on both screens
  1305.       BlitMode EraseMode
  1306.       Blit 68,sx,sy
  1307.       BlitMode CookieMode
  1308.       BBlit draw,0,sx,sy ;but buffer-blit the one card back
  1309.       Gosub Newpage
  1310.     Next
  1311.   EndIf
  1312.   noise=18               ;ok, make a sound
  1313.   Gosub makenoise
  1314. Return
  1315.  
  1316. .Compget                 ;pick up a card
  1317.   Gosub Grabcard         ;and send it to the computer's hand
  1318.   Repeat
  1319.     If sx>cx+4 Then sx-4 ;this stuff moves the
  1320.     If sx>cx Then sx-1   ;card toward the next spot in
  1321.     If sx<cx Then sx+2   ;the computer's hand and slows
  1322.     If sy>cy Then sy-1   ;down when it gets close so we
  1323.     shp=0                ;can hit the exact spot
  1324.     Gosub Draw
  1325.   Until sx=cx AND sy=cy
  1326.   noise=13
  1327.   Gosub makenoise        ;make a sound when it gets there
  1328.   Ccards+1               ;update the amount of cards
  1329.   Chand(Ccards,0)=card   ;and the computer array
  1330.   cx+6                   ;reset position for next card
  1331.   Gosub Drawdone
  1332. Return
  1333.  
  1334. .Playerget                 ;player picks up a card
  1335.   Gosub Grabcard           ;get next card from deck
  1336.   If card=-1 Then Return   ;wait a minute-all cards GONE!
  1337.   Pcards+1                 ;add one to our count
  1338.   Sortflag=0               ;and re-set the sort flag
  1339.   Repeat
  1340.     If sx>Ppos(Pcards,0)+4 Then sx-4    ;this slides the card
  1341.     If sx>Ppos(Pcards,0) Then sx-1      ;into the player's hand
  1342.     If sx<Ppos(Pcards,0)-4 Then sx+4    ;just like computer above
  1343.     If sx<Ppos(Pcards,0) Then sx+1
  1344.     If sy<Ppos(Pcards,1) Then sy+2
  1345.     Gosub Draw
  1346.   Until sx=Ppos(Pcards,0) AND sy=Ppos(Pcards,1)
  1347.   Phand (Pcards)=card      ;and update player's array
  1348.   flip=up                  ;but we have to flip the player's
  1349.   Gosub Flipit             ;cards face up so we can see it
  1350. Return
  1351.  
  1352. .PrintMessage                 ;this prints message in the message box
  1353.   Use BitMap draw             ;on the draw page
  1354.   Boxf 4,185,314,196,3        ;and copies it to the other page
  1355.   BPrint{Message$,160,0,192}
  1356.   Use BitMap see
  1357.   Scroll 0,185,320,11,0,185,draw
  1358.   Use BitMap draw
  1359. Return
  1360.  
  1361. .getmouse       ;wait for a mouseclick or keypress
  1362.   setPointer {normal,0}    ;regular pointer
  1363.   FlushEvents $8 ;clear any prior mouse events (for the trigger-happy user)
  1364.   ev.l=WaitEvent         ;multi-task until response detected
  1365.   If EventWindow=0
  1366.     If sleep >0          ;program was sleeping (screen hidden)
  1367.       If sleep = 1       ;turn music on
  1368.         CacheClearU_
  1369.         VWait 10
  1370.         If Forced=2      ;force screenmode if it was done before
  1371.           ForcePAL
  1372.         EndIf
  1373.         If Forced=1
  1374.            ForceNTSC
  1375.         EndIf
  1376.         music=1          ;fix the music flag
  1377.         Gosub MusicOn    ;and re-start it
  1378.         Message$=txt$(2)
  1379.         Gosub PrintMessage
  1380.         sleep=0
  1381.         Gosub Drawdone
  1382.         Gosub buttonUp
  1383.         Goto getmouse
  1384.       EndIf
  1385.     EndIf
  1386.     If ev=$400           ;key was pressed
  1387.       t$=Inkey$
  1388.       If t$=Chr$(27)     ;ESC key
  1389.         hit=2
  1390.         Return
  1391.       EndIf
  1392.  
  1393.       If t$="p"
  1394.         noise =4
  1395.         Gosub makenoise
  1396.         VWait
  1397.         ForcePAL
  1398.         Forced=2
  1399.       EndIf
  1400.       If t$="n"
  1401.         noise=4
  1402.         Gosub makenoise
  1403.         VWait
  1404.         ForceNTSC
  1405.         Forced=1
  1406.       EndIf
  1407.       If t$="m" OR t$="M"      ;user wants to toggle music off/on
  1408.         If ModOn=1             ;we have loaded a mod
  1409.           If music=1           ;so do it
  1410.             Gosub fademusic    ;but if off, do it gracefully
  1411.             music=0
  1412.           Else
  1413.             music=1            ;was off, turn it on
  1414.             Gosub MusicOn      ;put a coin in the jukebox
  1415.           End If
  1416.         Else                   ;NO MOD IN MEMORY!!!
  1417.           ShowBitMap 0
  1418.           dummy=RTreq {txt$(60),txt$(63),txt$(64)}
  1419.           ShowBitMap see
  1420.         EndIf
  1421.       End If
  1422.       Goto getmouse            ;go back & wait for mousebutton
  1423.     End If
  1424.  
  1425.     btn=1                      ;left button down
  1426.     If Joyb(0)=2 Then btn=2    ;right button
  1427.     setPointer{buttondown,0}   ;show button down pointer
  1428.     Gosub buttonUp             ;wait till mousebutton is released
  1429.     mx=EMouseX                 ;and get the
  1430.     my=EMouseY                 ;pointer's position
  1431.     FlushEvents                ;again, save the trigger-happy
  1432.   Return                      ;and continue the program
  1433. EndIf
  1434. Goto getmouse
  1435.  
  1436. .buttonUp
  1437.  Repeat                     ;now wait
  1438.    ev.l=WaitEvent           ;for mousebutton
  1439.  Until ev=$8 AND Joyb(0)=0  ;till it is released
  1440.  setPointer{normal,0}       ;use regular pointer
  1441. Return
  1442.  
  1443. HitWhat             ;this determines what was clicked
  1444.   hit=0             ;first we reset the flags
  1445.   PlayCard=0
  1446.   If RectsHit (mx,my,1,1,221,67,22,30) Then hit=1 ; draw a card
  1447.   If RectsHit (mx,my,1,1,257,9,27,9) Then hit=2 ; menu button
  1448.   If RectsHit (mx,my,1,1,225,9,27,9) Then hit=4 ; sort button
  1449.   If RectsHit (mx,my,1,1,290,9,27,9)   Then hit=5 ; hide bitton
  1450.   If hit>0 Then Return  ;Got it! we don't need to check for cards
  1451.   check=1
  1452.   If Pcards=1 Then Goto fullcheck ;only one card left!
  1453.   checkcards   ;checks all the visible card positions from left
  1454.   If RectsHit (mx,my,1,1,Ppos(check,0)-11,Ppos(check,1)-15,11,30)
  1455.     hit=3
  1456.     PlayCard=Phand(check)
  1457.     Inhand=check
  1458.   EndIf
  1459.   check+1
  1460.   If PlayCard=0 AND check <Pcards Then Goto checkcards ;nope, try next
  1461.  
  1462.   fullcheck ;the last card on right is bigger so we check full area
  1463.   If RectsHit (mx,my,1,1,Ppos(check,0)-11,Ppos(check,1)-15,22,30)
  1464.     hit=3
  1465.     PlayCard=Phand(check)
  1466.     Inhand=check
  1467.   EndIf
  1468. Return
  1469.  
  1470. .WhatCard      ;determine the suit & rank of a card from its number
  1471.   Suit=0       ;set to first suit
  1472.   Rank=card    ;this is the card's number
  1473.  
  1474. checksuit
  1475.   If Rank>13        ;only 13 cards per suit
  1476.     Suit+1          ;so go to next suit
  1477.     Rank-13         ;and subtract 13
  1478.     Goto checksuit  ;and try again
  1479.   EndIf
  1480.   ok=0                                              ;now reset flag
  1481.   If Suit=CSuit OR Rank=CRank OR Rank=8 Then ok=1   ;and check for
  1482. Return                                              ;playability
  1483.  
  1484. .Pullcard           ;pull a card out of the player's hand
  1485.   sx=Ppos(Inhand,0)            ;get the drawing positions from
  1486.   sy=Ppos(Inhand,1)            ;the player position array
  1487.   shp=card                     ;and set the drawing shape
  1488.   Row=1:Rowflag=1:temp2=Pcards ;reset the flags to 1 row of cards
  1489.   If Inhand>25 Then Row=2      ;card selected from second row
  1490.   If Pcards>25 Then Rowflag=2  ;player has TWO rows of cards
  1491.   If Row=1 AND Rowflag=2 Then temp2=25  ;but he selected from top row
  1492.   For q=1 To 2                 ;set up both pages
  1493.     BlitMode EraseMode
  1494.     Blit 68,sx,sy              ;draw blank shape to erase
  1495.     BlitMode CookieMode
  1496.     If Inhand>1 AND Inhand<>26 Then Blit Phand(Inhand-1),Ppos(Inhand-1,0),Ppos(Inhand-1,1)
  1497.     BBlit draw,shp,sx,sy       ;and buffer blit the card
  1498.      If Inhand<>Pcards AND Inhand <>25   ;if not last card in row
  1499.       For j= Inhand+1 To temp2           ;re draw other cards to
  1500.         Blit Phand(j),Ppos(j,0),Ppos(j,1);the right of selected one
  1501.       Next
  1502.      EndIf
  1503.    Gosub Newpage              ;and switch pages
  1504.   Next q                      ;do the other page
  1505.    If Inhand=Pcards OR Inhand=25 Then Goto ready ;if last card
  1506.    For i=0 To 12 Step 2       ;otherwise, move cards to right
  1507.      sy-5                     ;over to fill the space
  1508.      Gosub MoveEm
  1509.    Next i
  1510.    i=12
  1511.    Gosub MoveEm
  1512.  
  1513. ready                  ;ok all done
  1514.   ShowBitMap see
  1515.   VWait
  1516.   Use BitMap draw
  1517.   Return
  1518.  
  1519. MoveEm
  1520.   UnBuffer draw
  1521.   BBlit draw,shp,sx,sy
  1522.   BlitMode EraseMode
  1523.   Blit 68,Ppos(temp2,0),Ppos(temp2,1)
  1524.   BlitMode CookieMode
  1525.   For j= Inhand+1 To temp2
  1526.     Blit Phand(j),Ppos(j,0)-i,Ppos(j,1)
  1527.   Next j
  1528.   Gosub Newpage
  1529. Return
  1530.  
  1531. MoveUp
  1532.  temp3=Inhand
  1533.  Inhand=26
  1534.  card=Phand(26)
  1535.  Gosub Pullcard
  1536.  Repeat
  1537.   If sx<Ppos(25,0) Then sx+2
  1538.   If sx<Ppos(25,0)-6 Then sx+4
  1539.   If sx>200 AND  sy<128 Then sy+1
  1540.   If sy>128 Then sy-1
  1541.   Gosub Draw
  1542.  Until sy=128 AND sx=Ppos(25,0)
  1543.  Gosub Drawdone
  1544.  Inhand=temp3
  1545. Return
  1546.  
  1547.  
  1548.  
  1549. .CompPlay
  1550.  cx-6:sx=cx:sy=cy:card=Chand(cplay,0)
  1551.  For i=1 To 2
  1552.    BlitMode EraseMode
  1553.    Blit 68,sx,sy
  1554.    BlitMode CookieMode
  1555.    If Ccards>1 Then Blit 0,sx-6,sy
  1556.    BBlit draw,0,sx,sy
  1557.    Gosub Newpage
  1558.  Next
  1559.  flip=up
  1560.  Gosub Flipit
  1561.  For i=cplay To Ccards
  1562.    Chand(i,0)=Chand(i+1,0)
  1563.  Next
  1564.  For i=1 To 2
  1565.    BlitMode EraseMode
  1566.    Blit 68,sx,sy
  1567.    BlitMode CookieMode
  1568.    If Ccards>1 Then Blit 0,sx-6,sy
  1569.    BBlit draw,card,sx,sy
  1570.    Gosub Newpage
  1571.  Next
  1572.  Ccards-1
  1573. Return
  1574.  
  1575. .SetSuit
  1576.   If Pcards=0 OR Ccards=0 Then Return
  1577.   If compflag=0 AND Sortflag=0 AND pickup>0 Then Gosub Sorthand
  1578.   Message$=txt$(40)  ;"O.K.  Choose Your Suit"
  1579.   If compflag=1
  1580.     If WildHair
  1581.       Message$="WildHair!"
  1582.     Else
  1583.       Message$=txt$(41)  ;"Hmmmmm.  Let's see!"
  1584.     EndIf
  1585.   EndIf
  1586.   Gosub PrintMessage
  1587.   noise=23:Gosub makenoise
  1588.   ShowBitMap draw
  1589.   VWait
  1590.   Use BitMap draw
  1591.   Blit 59,88,82
  1592.   Blit 58,40,82
  1593.   If compflag=1
  1594.     If WildHair AND Cmost=CSuit
  1595.       Cmost+1
  1596.       If Cmost=4 Then Cmost=0
  1597.     EndIf
  1598.     Suit=Cmost
  1599.     Message$=txt$(41)
  1600.     VWait 150
  1601.     Goto useit
  1602.   EndIf
  1603.  
  1604. playerpick
  1605.   Gosub getmouse
  1606.   Suit=5
  1607.   temp=8
  1608.   For i=0 To 3
  1609.     If RectsHit(mx,my,1,1,temp,71,14,15) Then Suit=i
  1610.     temp+15
  1611.   Next
  1612.   If Suit=5          ;bad selection!
  1613.     noise=3
  1614.     Gosub makenoise
  1615.     Goto playerpick
  1616.   EndIf
  1617.   Message$=txt$(43)
  1618.  
  1619. useit
  1620.  
  1621.   Use BitMap see
  1622.   Blit 60+Suit,88,82
  1623.   CSuit=Suit
  1624.   Gosub Drawdone
  1625.   noise=5
  1626.   Gosub makenoise
  1627.   Gosub PrintMessage
  1628.   If compflag=1
  1629.     noise=21
  1630.   Else
  1631.     noise=26
  1632.     If Pcards<3 Then noise=33
  1633.   EndIf
  1634.   Gosub makenoise
  1635.   VWait 100
  1636. Return
  1637.  
  1638. .Sorthand
  1639.  Rowflag=1
  1640.  If Pcards>25 Then Rowflag=2
  1641.  card=Phand(Pcards)
  1642.  sx=Ppos(Pcards,0)
  1643.  sy=Ppos(Pcards,1)
  1644.  dx=Ppos(1,0)
  1645.  Gosub Slideleft
  1646.  If Rowflag=2
  1647.    sx=Ppos(25,0)
  1648.    sy=Ppos(25,1)
  1649.    card=Phand(25)
  1650.    Gosub Slideleft
  1651.  EndIf
  1652.  For i= Pcards+1 To 52
  1653.    Phand(i)=60
  1654.  Next
  1655.  Sort Phand()
  1656.  card=Phand(Pcards)
  1657.  sx=Ppos(1,0)
  1658.  sy=Ppos(Pcards,1)
  1659.  temp=1
  1660.  temp2=Pcards
  1661.  If Rowflag=2 Then temp=26
  1662.  Gosub Slideright
  1663.  If Rowflag=2
  1664.    Rowflag=1
  1665.    sx=Ppos(1,0)
  1666.    sy=Ppos(1,1)
  1667.    card=Phand(25)
  1668.    temp=1
  1669.    temp2=25
  1670.    Gosub Slideright
  1671.  EndIf
  1672.  Sortflag=1
  1673. Return
  1674.  
  1675. Slideright
  1676.   flip=up
  1677.   Gosub Flipit
  1678.   noise=18:Gosub makenoise
  1679.   dx=Ppos(temp2,0)
  1680.   If sx<>dx
  1681.     Repeat
  1682.       sx+4
  1683.       For i=temp To temp2
  1684.         If sx>Ppos(i,0) AND sx<Ppos(i,0)+20
  1685.           Blit Phand(i),Ppos(i,0),Ppos(i,1)
  1686.         EndIf
  1687.       Next
  1688.       Blit card,sx,sy
  1689.       Gosub Newpage
  1690.     Until sx=dx
  1691.   EndIf
  1692.   Gosub Drawdone
  1693. Return
  1694.  
  1695. Slideleft
  1696.   noise=18:Gosub makenoise
  1697.   If sx<>dx
  1698.     Repeat
  1699.       BlitMode EraseMode
  1700.       Blit 68,sx+3,sy
  1701.       BlitMode CookieMode
  1702.       sx-3
  1703.       Blit card,sx,sy
  1704.       Gosub Newpage
  1705.     Until sx=dx
  1706.   EndIf
  1707.   Gosub Drawdone
  1708.   flip=down
  1709.   Gosub Flipit
  1710. Return
  1711.  
  1712. .Score
  1713.  VWait 15
  1714.  card=shp
  1715.  Gosub WhatCard
  1716.  If Rank>10 Then Rank=10
  1717.  If Rank=1
  1718.    Rank=20
  1719.    noise=1+15*playerflag
  1720.    Gosub makenoise
  1721.  EndIf
  1722.  If Rank=8
  1723.    Rank=50
  1724.    noise=7+3*playerflag
  1725.    Gosub makenoise
  1726.  EndIf
  1727.  noise=14+playerflag
  1728.  Gosub makenoise
  1729.  If (playerflag=0 AND scoreon=0) OR (playerflag=1 AND scoreon=1)
  1730.    Pscore=Pscore+Rank
  1731.  Else
  1732.    Cscore=Cscore+Rank
  1733.  EndIf
  1734.  
  1735. showscore            ;update the score box
  1736.  Format "000"        ;with three number format
  1737.  BitMapOutput see    ;just use the seen page
  1738.  Colour 7,1          ;gold on black
  1739.  Locate 23,9.9
  1740.  Print Str$(Cscore)  ;Computer's score
  1741.  Locate 23,11
  1742.  Print Str$(Pscore)  ;Player's score
  1743.  Gosub Drawdone
  1744.  VWait 35
  1745. Return
  1746.  
  1747. .showCcards           ;show computer cards in hand
  1748.   Format "00"         ;use two number format
  1749.   BitMapOutput see    ;use the seen page
  1750.   Colour 7,1          ;gold on black
  1751.   Locate 2,.8
  1752.   Print Str$(Ccards)  ;how many cards we're holding
  1753.   BitMapOutput draw   ;use the unseen page
  1754.   Locate 2,.8
  1755.   Print Str$(Ccards)  ;how many cards we're holding
  1756.   VWait hold+1           ;and make sure it's seen
  1757. Return
  1758.  
  1759.  
  1760. .Playcard
  1761.  Repeat
  1762.    If sx<84 Then sx+4
  1763.    If sx<88 Then sx+1
  1764.    If sx>92 Then sx-4
  1765.    If sx>88 Then sx-1
  1766.    If sy>85 Then sy-3
  1767.    If sy>82 Then sy-1
  1768.    If sy<80 Then sy+2
  1769.    If sy<82 Then sy+1
  1770.    Gosub Draw
  1771.  Until sx=88 AND sy=82
  1772.  Gosub Drawdone
  1773.  Dpile+1
  1774.  Pile(Dpile)=card
  1775.  Gosub WhatCard
  1776.  CSuit=Suit
  1777.  CRank=Rank
  1778. Return
  1779.  
  1780. .Prefs              ;Options window w/GT gadgets
  1781.   #LocString   = 51
  1782.   #BtnSave     = 52
  1783.   #LocReq      = 54
  1784.   #Music       = 55
  1785.   #SndFilter   = 56
  1786.   #LoseWinMX   = 58
  1787.   #ScoreMX     = 59
  1788.   #BtnUse      = 60
  1789.   #Pname       = 61
  1790.   #Cname       = 62
  1791.  
  1792.   Gosub makePlist     ;create the GTlist
  1793.  
  1794.   *gtscr.Screen = Peek.l (Addr Screen(0))
  1795.   offy.b = *gtscr\WBorTop + *gtscr\_RastPort\TxHeight +1
  1796.   fadeto{0,1}
  1797.   Window 1,0,0,320,200,$1000," "+c8$+" Prefs",1,2
  1798.   MenusOff
  1799.   offx.b = WLeftOff
  1800.   setPointer{normal,1}
  1801.   noise=14:Gosub makenoise
  1802.   Gosub drawWin
  1803.   fadeto{pl,1}
  1804.   split=0
  1805.  
  1806. .prefloop
  1807.  
  1808.   Repeat
  1809.     ev.l = WaitEvent
  1810.     If ev=$8
  1811.       Select MButtons
  1812.         Case 1
  1813.           setPointer{buttondown,1}
  1814.         Case 2
  1815.           setPointer{waitpointer,1}
  1816.         Case 5
  1817.           setPointer{normal,1}
  1818.         Case 6
  1819.           setPointer{normal,1}
  1820.       End Select
  1821.     EndIf
  1822.  
  1823.     If ev = #IDCMP_GADGETUP OR ev= #IDCMP_GADGETDOWN
  1824.       noise=13:Gosub makenoise
  1825.       If ev=$20
  1826.         setPointer{buttondown,1}
  1827.         Select GadgetHit
  1828.           Case #ScoreMX
  1829.             scbtn.b=EventCode
  1830.             Select scbtn
  1831.               Case 0
  1832.                 maxpoints=50
  1833.               Case 1
  1834.                 maxpoints=100
  1835.               Case 2
  1836.                 maxpoints=150
  1837.               Case 3
  1838.                 maxpoints=200
  1839.               Case 4
  1840.                 maxpoints=300
  1841.             End Select
  1842.  
  1843.           Case #LoseWinMX
  1844.             scoreon=EventCode
  1845.         End Select
  1846.       Else
  1847.         setPointer{normal,1}
  1848.         Select GadgetHit
  1849.           Case #SndFilter
  1850.             If Fltr.b=True
  1851.                Fltr=False
  1852.             Else
  1853.                Fltr=True
  1854.             EndIf
  1855.             Gosub setflt
  1856.           Case #BtnSave
  1857.             compname$=GTGetStr{0,62}
  1858.             playername$=GTGetStr{0,61}
  1859.             Gosub savepref
  1860.             VWait 60
  1861.             split=1
  1862.           Case #LocReq
  1863.             titl$=" "+c8$+" "+txt$(87)+":"
  1864.             newloc$= ASLFileRequest$ (titl$,locpa$,locfi$,0,12,320,188)
  1865.             If newloc$<>"" AND locfi$<>locale$
  1866.               locale$=locfi$
  1867.               Gosub GetLocale
  1868.               DetachGTList 0
  1869.               Free GTList 0
  1870.               fadeto{0,1}
  1871.               Gosub makePlist
  1872.               Gosub drawWin
  1873.               fadeto{pl,1}
  1874.             EndIf
  1875.           Case #Music
  1876.             If ModOn=1
  1877.                ModOn=0
  1878.                StopMed
  1879.                music=0
  1880.                Free MedModule 0
  1881.             Else
  1882.                ModOn=1
  1883.                ld$=pa$+"/"+fi$
  1884.                LoadMedModule 0,ld$
  1885.                music=1
  1886.                Gosub MusicOn
  1887.             EndIf
  1888.  
  1889.           Case #BtnUse
  1890.             split=1
  1891.             compname$=GTGetStr{0,62}
  1892.             playername$=GTGetStr{0,61}
  1893.         End Select
  1894.       EndIf
  1895.     EndIf
  1896.     FlushEvents
  1897.   Until split
  1898.   If playername$<>txt$(57)
  1899.     pgreet$=", "+playername$
  1900.   Else
  1901.     pgreet$=""
  1902.   EndIf
  1903.   split=0
  1904.   VWait
  1905.   Use Window 0
  1906.   fadeto{0,1}
  1907.   DetachGTList 0
  1908.   Free Window 1
  1909.   CopyBitMap 1,0
  1910.   Free GTList 0
  1911.   fadeto{pl,1}
  1912. Return
  1913.  
  1914. .makePlist
  1915.   t$=txt$(48)+"|"+txt$(49)
  1916.   GTText      0,#LocString,90,46,180,16,txt$(87),#PLACETEXT_LEFT,locale$
  1917.   GTButton    0,#LocReq,270,46,19,16,"?",#PLACETEXT_IN|$80
  1918.   GTCheckBox  0,#Music,26,77,26,11,txt$(46),#PLACETEXT_RIGHT|$80
  1919.   GTCheckBox  0,#SndFilter,202,77,26,11,txt$(47),#PLACETEXT_RIGHT|$80
  1920.   GTMX        0,#LoseWinMX,46,116,17,9,"",#PLACETEXT_RIGHT,t$,scoreon.b
  1921.   GTMX        0,#ScoreMX,208,113,17,9,"",#PLACETEXT_RIGHT," 50|100|150|200|300",scbtn.b
  1922.   GTButton    0,#BtnSave,8,167,80,16,txt$(45),#PLACETEXT_IN|$80
  1923.   GTButton    0,#BtnUse,228,167,80,16,txt$(50),#PLACETEXT_IN|$80
  1924.   GTString    0,#Pname,64,16,85,16,txt$(51),#PLACETEXT_LEFT|$80,8,playername$
  1925.   GTString    0,#Cname,214,16,85,16,"Amiga",#PLACETEXT_LEFT|$80,8,compname$
  1926. Return
  1927.  
  1928. drawWin
  1929.   InnerCls 3
  1930.   WJam 1
  1931.   If ModOn.b=1 Then GTSetAttrs  0,#Music, #GTCB_Checked, True
  1932.   If Fltr.b=True Then GTSetAttrs  0,#SndFilter, #GTCB_Checked, True
  1933.   WJam 0
  1934.   AttachGTList 0,1
  1935.   GTBevelBox 0,7+offx,1+offy,302,35,1
  1936.   GTBevelBox 0,7+offx,39+offy,302,28,1
  1937.   GTBevelBox 0,7+offx,70+offy,302,25,1
  1938.   GTBevelBox 0,7+offx,98+offy,302,68,1
  1939.   WColour 1,0
  1940.   WLocate 28,104 : Print txt$(52)
  1941.   WLocate 198,102 : Print txt$(53)
  1942.   WColour 4,0
  1943.   WLocate 115,5 : Print txt$(55)
  1944. Return
  1945.  
  1946. .LoadMed
  1947. ld$=defmed$
  1948. newmod$=ASLFileRequest$(txt$(56),pa$,fi$,0,0,320,200)
  1949. Gosub FixBar
  1950. .CheckMed
  1951. If newmod$<>""
  1952.   If prefload.b=0
  1953.     Message$=Chr$(133)+" "+fi$+" "+Chr$(134)
  1954.     Gosub PrintMessage
  1955.   EndIf
  1956.   If ReadFile(0,newmod$)
  1957.     FileInput 0
  1958.     A$ = Edit$(12)    ; Read 12 bytes or upto a chr$(10)
  1959.     CloseFile 0
  1960.     Use Window 0
  1961.     If Left$(A$,3)= "MMD" AND Right$(A$,1) = "4"  ; OK, 4 channel MED
  1962.       size.l=Exists(newmod$)                    ;check mod length
  1963.       If music=1 Then Gosub fademusic
  1964.       Free MedModule 0                          ;can old mod
  1965.       VWait 10
  1966.       chips.l=ChipFree                          ;check chip mem
  1967.       If chips>size+5000                        ;ok to load new mod
  1968.         ld$=newmod$                             ;so change name
  1969.         defpa$=pa$
  1970.         deffi$=fi$
  1971.       Else                                      ;short on chip mem!
  1972.         A$=txt$(68)+" = "+Str$(chips)
  1973.         B$=txt$(69)+" "+Str$(size+5000)+"|"+txt$(70)
  1974.         dummy=RTreq{A$,B$,txt$(61)}
  1975.         pa$=defpa$
  1976.         fi$=deffi$
  1977.       EndIf
  1978.     ld$=pa$+"/"+fi$
  1979.     VWait 10
  1980.     LoadMedModule 0,ld$
  1981.     music=1
  1982.     Gosub MusicOn
  1983.     Else    ; not a 4 channel med!
  1984.       dummy=RTreq{txt$(65),txt$(67),txt$(61)}
  1985.     EndIf
  1986.   Else      ; can't even find it!
  1987.     dummy=RTreq{txt$(65),txt$(66),txt$(64)}
  1988.   EndIf
  1989. EndIf
  1990. If prefload=0
  1991.   Message$=txt$(1)
  1992.   Gosub PrintMessage
  1993. EndIf
  1994. Return
  1995.  
  1996. .LoadSounds
  1997. snderr.b=0
  1998.  
  1999. For i=0 To 33
  2000.   Timeout(i)=0
  2001.   Free Sound i
  2002.   lsd$=snd$+sd$(i)               ;now load the sounds
  2003.   lnth.l=Exists(lsd$)
  2004.   If lnth>0 AND ChipFree > lnth
  2005.     If ReadFile(0,lsd$)
  2006.       FileInput 0
  2007.       temp$=Inkey$(12)
  2008.       CloseFile 0
  2009.       Use Window 0
  2010.       ;If Right$(temp$,4)="8SVX"
  2011.       If Instr(temp$,"8SVX")
  2012.         LoadSound i,lsd$
  2013.         CacheClearU_
  2014.         soundnumber.w=i
  2015.         Gosub SoundDelay
  2016.         Timeout(i)=delay.w
  2017.       Else
  2018.         snderr+1
  2019.       EndIf
  2020.     Else
  2021.       snderr+1
  2022.     EndIf
  2023.   EndIf
  2024. Next
  2025. If snderr>0 AND showerr=True
  2026.   Format ""
  2027.   dummy=RTreq{txt$(60),txt$(66)+"|"+Str$(snderr)+" "+txt$(76),txt$(64)}
  2028. EndIf
  2029.  
  2030. Return
  2031.  
  2032. .FinishSound    ;wait until the sound is done
  2033. If hold>0
  2034.   Repeat
  2035.     VWait
  2036.   Until hold=0
  2037. EndIf
  2038. Return
  2039. ;determine the playing time of the samples
  2040.  
  2041. .SoundDelay
  2042.  
  2043. period.q=Peek.w(Addr Sound (soundnumber)+4)     ;get the period from sound object
  2044. lngth.l=(Peek.w(Addr Sound (soundnumber)+6) AND $FFFF)*2  ;get the length from sound object
  2045. frequency.f = 3579440/period                    ;convert to true frequency
  2046. delay.w=lngth/(frequency/vrate)                 ;convert to playing time in VBlanks
  2047. delay+5                                         ;add a bit of padding for short samples
  2048. Return
  2049.  
  2050. .makenoise
  2051. If Timeout(noise)>0
  2052.   SetMedMask 3
  2053.   hold=Timeout(noise)
  2054.   Sound noise,12
  2055. EndIf
  2056. Return
  2057.  
  2058. .fademusic
  2059. If ModOn
  2060.   For i=64 To 0 Step -1
  2061.     SetMedVolume i
  2062.     VWait 2
  2063.   Next
  2064.   StopMed
  2065.   SetMedVolume 64
  2066.   playing.b=0
  2067. EndIf
  2068. Return
  2069.  
  2070. .MusicOn
  2071.   If ModOn=1 AND playing.b=0
  2072.     StartMedModule 0
  2073.     playing=1
  2074.   EndIf
  2075.  
  2076. setflt
  2077.   If Fltr=False
  2078.     Filter On
  2079.   Else
  2080.     Filter Off
  2081.   EndIf
  2082. Return
  2083.  
  2084. .CompComplain           ;complain in print and sound
  2085.   complain=complain + 1         ;and set a new complaint so we
  2086.   If complain>9 Then complain=1 ;don't say the same thing all the time
  2087.   Gosub makenoise
  2088. Return
  2089.  
  2090. .CompNoise
  2091.   Select complain               ;select a noise
  2092.        Case 1
  2093.         noise=25
  2094.        Case 2
  2095.         noise=30
  2096.        Case 3
  2097.         noise=24
  2098.        Case 4
  2099.         noise=29
  2100.        Case 5
  2101.         noise=16
  2102.        Case 6
  2103.         noise=31
  2104.        Case 7
  2105.         noise=1
  2106.        Case 8
  2107.         noise=7
  2108.        Case 9
  2109.         noise=32
  2110.     End Select
  2111. Return
  2112.  
  2113. .savepref
  2114.   temp$=playername$
  2115.   If temp$=txt$(57) Then temp$="Default"
  2116.   rq$=txt$(84)+Chr$(10)+txt$(85)
  2117.   titl$=txt$(82)+" "+txt$(77)
  2118.   save$=RTEZGetString(titl$,rq$,30,temp$)
  2119.   If save$<>""
  2120.     temp$=save$+".8's"
  2121.     prefname$=ourpath$+"/"+temp$
  2122.     If WriteFile (0,prefname$)             ;open pref file
  2123.       ;ResetTimer
  2124.       ;Gosub PrintMessage
  2125.       FileOutput 0
  2126.       NPrint compname$                     ;computer's name
  2127.       NPrint playername$                   ;player's name
  2128.       NPrint Fltr                          ;audio filter on or off
  2129.       NPrint pa$                           ;default path
  2130.       NPrint fi$                           ;mod name
  2131.       NPrint scbtn                         ;mx scorebutton selected
  2132.       NPrint maxpoints.w                   ;default top score
  2133.       NPrint scoreon                       ;add points to looser if 0
  2134.       NPrint pl                            ;save the palette
  2135.       NPrint ModOn                         ;use music if 1
  2136.       NPrint snd$                          ;current sample set
  2137.       NPrint cardpic$                      ;current card pic
  2138.       NPrint locale$                       ;current locale
  2139.       CloseFile 0
  2140.       WindowOutput 1
  2141.       If LCase$ (save$)<>"default.8's"
  2142.         temp$=ourpath$+"/Icons/.8's.info"
  2143.         temp2$=prefname$+".info"
  2144.         If Exists(temps$) AND (Exists(temp2$) = 0)
  2145.           dummy=CopyFile(temp$,temp2$)
  2146.         EndIf
  2147.       EndIf
  2148.       Message$=save$+" "+txt$(74)+" "+txt$(79)
  2149.       Gosub PrintMessage
  2150.     Else
  2151.       dummy=RTreq{txt$(60),txt$(71),txt$(64)}
  2152.     EndIf
  2153.   EndIf
  2154. Return
  2155.  
  2156. .loadpref
  2157.   If ReadFile (0,pref$)                  ;open selected pref file
  2158.     FileInput 0
  2159.     compname$=Edit$(15)                  ;computer's name
  2160.     playername$=Edit$(15)                ;player's name
  2161.     Fltr.b=Edit(6)                       ;audio filter on or off
  2162.     pa$=Edit$(200)                       ;default path
  2163.     fi$=Edit$(200)
  2164.     scbtn.b=Edit(6)                      ;mx scorebutton selected
  2165.     maxpoints.w=Edit(6)                  ;default top score
  2166.     scoreon.b=Edit(6)                    ;add points to looser if 0
  2167.     pl.b=Edit(6)                         ;get the palette
  2168.     ModOn.b=Edit(6)                      ;use music if 1
  2169.     snd$=Edit$(256)                      ;sample path
  2170.     cardpic$=Edit$(256)                  ;card picture
  2171.     If NOT Eof(0)
  2172.       newloc$=Edit$(256)                 ;selected locale
  2173.     EndIf
  2174.     CloseFile 0
  2175.     WindowInput 0
  2176.  
  2177.   Else                                   ;Use Defaults
  2178.     compname$="Amiga"                    ;computer's name
  2179.     playername$=txt$(57)                 ;player's name
  2180.     Fltr.b=False                         ;audio filter on or off
  2181.     pa$="data/Mods"                      ;default path
  2182.     fi$="Med.Moonshine"                  ;default module name
  2183.     scbtn.b=3                            ;mx scorebutton selected
  2184.     maxpoints.w=200                      ;default top score
  2185.     scoreon.b=0                          ;add points to looser if 0
  2186.     ModOn.b=1
  2187.     pl.b=1
  2188.     snd$="sounds/original/"
  2189.     cardpic$="cards/3d.Deck"
  2190.   EndIf
  2191.   defpa$=pa$
  2192.   deffi$=fi$
  2193.   mmd$=pa$
  2194.   If Right$(pa$,1)<>":" AND Right$(pa$,1)<>"/"
  2195.     mmd$+"/"
  2196.   EndIf
  2197.   mmd$+fi$
  2198.   If newloc$="" Then newloc$=locale$
  2199.  
  2200. Return
  2201.  
  2202. .getSoundPath    ;select the Samples directory with a listview
  2203.  
  2204. dirs.w=0                         ;number of entries found
  2205. showme.w=0                       ;the current selection
  2206. drnow$=UnLeft$(Mid$(snd$,8),1)
  2207. drawer$=ourpath$+"/sounds/"
  2208. ChDir drawer$                    ; CD to the sounds/ directory
  2209. ResetList sndDrawers()
  2210. While MoreEntries                ; check if there's any more entries
  2211.   File_Name$=EntryName$          ; get its name
  2212.   If EntryDIR                    ; check if its a directory
  2213.     If File_Name$=drnow$
  2214.       showme=dirs
  2215.     EndIf
  2216.     dirs+1                       ;yes, so increase the directory count
  2217.     If AddItem(sndDrawers())
  2218.       sndDrawers()\string=" "+File_Name$
  2219.     EndIf
  2220.   EndIf
  2221. Wend
  2222. GTTags #GTLV_ShowSelected,0,#GTLV_MakeVisible,showme
  2223. GTListView 2,51,0,0,290,160,"",0,sndDrawers(),showme,0
  2224. AddIDCMP #INTUITICKS
  2225. AddIDCMP #MOUSEMOVE
  2226. VWait
  2227. CacheClearU_
  2228. titl$=" "+c8$+" "+txt$(76)+":"
  2229. Window 2,10,20,300,173,$1000,titl$,1,2
  2230. SubIDCMP #INTUITICKS|#MOUSEMOVE
  2231. MenusOff
  2232. AttachGTList 2,2
  2233. Repeat
  2234.   ev.l=WaitEvent
  2235.   If ev=$40
  2236.     showme=EventCode
  2237.   EndIf
  2238. Until ev=$40 AND EventWindow=2
  2239. ResetList sndDrawers()
  2240. For i = 0 To showme
  2241.   dummy=NextItem(sndDrawers())
  2242. Next
  2243. nsnd$=Mid$(sndDrawers()\string,2)
  2244. newsnd$="sounds/"+nsnd$+"/"
  2245. DetachGTList 2
  2246. Free GTList 2
  2247. Free Window 2
  2248. Use Window 0
  2249. ClearList sndDrawers()
  2250. ChDir ourpath$
  2251. Return
  2252.  
  2253. .getPref    ;select the Prefs with a listview
  2254.  
  2255. pfiles.w=0                         ; number of entries found
  2256. picked.w=0                         ; the current selection
  2257. ChDir ourpath$                     ; CD to the C8/ directory
  2258. ResetList sndDrawers()
  2259. While MoreEntries                  ; check if there's any more entries
  2260.   File_Name$=EntryName$            ; get its name
  2261.   If EntryDIR=0                    ; check if its a directory
  2262.     If Right$(File_Name$,4)=".8's" AND File_Name$<>"Crazy.8's"
  2263.       If AddItem(sndDrawers())
  2264.         If File_Name$=pref$ Then picked=pfiles
  2265.         sndDrawers()\string=" "+File_Name$
  2266.         pfiles+1
  2267.       EndIf
  2268.     EndIf
  2269.   EndIf
  2270. Wend
  2271. If pfiles
  2272.   CloseWindow 1
  2273.   GTTags #GTLV_ShowSelected,0,#GTLV_MakeVisible,picked
  2274.   GTListView 2,51,0,0,290,160,"",0,sndDrawers(),picked,0
  2275.   AddIDCMP #INTUITICKS
  2276.   AddIDCMP #MOUSEMOVE
  2277.   VWait
  2278.   CacheClearU_
  2279.   titl$=" "+c8$+" "+txt$(74)+":"
  2280.   Window 2,10,20,300,173,$1000,titl$,1,2
  2281.   SubIDCMP #INTUITICKS|#MOUSEMOVE
  2282.   MenusOff
  2283.   AttachGTList 2,2
  2284.   Repeat
  2285.     ev.l=WaitEvent
  2286.     If ev=$40
  2287.       picked=EventCode
  2288.     EndIf
  2289.   Until ev=$40 AND EventWindow=2
  2290.   ResetList sndDrawers()
  2291.   For i = 0 To picked
  2292.     dummy=NextItem(sndDrawers())
  2293.   Next
  2294.   pref$=Mid$(sndDrawers()\string,2)
  2295.   DetachGTList 2
  2296.   Free GTList 2
  2297.   Free Window 2
  2298.   Use Window 0
  2299.   ClearList sndDrawers()
  2300. Else
  2301.   pref$=""
  2302. EndIf
  2303. Return
  2304.  
  2305. .GetLocale
  2306.   If Exists("locale/"+locale$)=0
  2307.     temp$=Language{}
  2308.     If Exists("locale/"+temp$)
  2309.       locale$=temp$
  2310.     Else
  2311.       titl$=" "+c8$+" "+txt$(87)+":"
  2312.       locpa$="locale/"
  2313.       locale$= ASLFileRequest$ (titl$,locpa$,locfi$,0,12,320,188)
  2314.     EndIf
  2315.   EndIf
  2316.   If ReadFile (0,"locale/"+locale$)
  2317.     FileInput 0
  2318.     t$=Edit$(180)
  2319.     If Left$(t$,2)<>"C8"
  2320.       CloseFile 0
  2321.       WindowInput 0
  2322.       Goto badlocale
  2323.     EndIf
  2324.     If Mid$(t$,3,1)=" "
  2325.       font$="C8"
  2326.     Else
  2327.       font$=Left$(t$,3)
  2328.     EndIf
  2329.     font$+".font"
  2330.     Gosub newfont
  2331.     If playername$=txt$(57) Then playername$=""
  2332.     locld$=ReadLoc{}
  2333.     locby$=ReadLoc{}
  2334.     If Mid$(t$,4,3)="2.9" ;good, a newer one!
  2335.       transby$=locby$
  2336.       trans1$=ReadLoc{}
  2337.       locby$+"|"+trans1$    ;the string for "About" bit
  2338.       locand$=ReadLoc{}     ;and
  2339.       trans2$=ReadLoc{}     ;second translator or ...
  2340.       If trans2$<>"..."
  2341.         locby$+"|"+locand$+"|"+trans2$
  2342.       EndIf
  2343.       t$=ReadLoc{}
  2344.       If t$<>"..."
  2345.         locby$+"|"+"("+t$+")"
  2346.       EndIf
  2347.     Else
  2348.       If Len(locby$)>32
  2349.         locby$=Right$(locby$,32)
  2350.       EndIf
  2351.       For i = 1 To 4
  2352.         t$=ReadLoc{}
  2353.       Next
  2354.     EndIf
  2355.     yes$=ReadLoc{}
  2356.     done.b=0
  2357.     i=0
  2358.     Repeat                  ;now read in all the strings
  2359.       If Eof(0)=-1 OR i>87
  2360.         done=1
  2361.       Else
  2362.         temp$=ReadLoc{}
  2363.         If temp$="-1"
  2364.           done=1
  2365.           i-1
  2366.         Else
  2367.           txt$(i)=temp$
  2368.           i+1
  2369.         EndIf
  2370.       EndIf
  2371.     Until done
  2372.     CloseFile 0
  2373.     WindowInput 0
  2374.     If i<86
  2375.       dummy=RTreq{"Locale Error","Missing some text|Please read the Docs!","OK"}
  2376.     EndIf
  2377.     If i=86 Then txt$(87)="Locale"
  2378.     If playername$="" Then playername$=txt$(57)
  2379.     If playername$<>txt$(57)
  2380.       pgreet$=", "+playername$
  2381.     Else
  2382.       pgreet$=""
  2383.     EndIf
  2384.     temp$=Replace$ (txt$(0),"^",Chr$(133))
  2385.     txt$(0)=Replace$ (temp$,"_",Chr$(134))
  2386.   Else
  2387.   badlocale
  2388.     dummy=RTreq{"Locale Error","Can't load Locale file|Please read the docs","Darn!"}
  2389.     If setup=0 Then End
  2390.   EndIf
  2391.  Return
  2392. .ScoreTable
  2393.  
  2394. If Exists("c8.scores")         ;read in the saved scores, if any
  2395.   If ReadFile(0,"c8.scores")
  2396.     FileInput 0
  2397.     entries.w=Edit(8)
  2398.     i=1
  2399.     While NOT Eof(0)
  2400.       scorename$(i)=Edit$(30)
  2401.       gamesplayed(i)=Edit(6)
  2402.       gameswon(i)=Edit(6)
  2403.       i+1
  2404.     Wend
  2405.     CloseFile 0
  2406.     WindowInput 0
  2407.     Use Window 0
  2408.   EndIf
  2409. Else
  2410.   entries=2
  2411.   scorename$(1)=playername$
  2412.   scorename$(2)=compname$
  2413. EndIf
  2414.  
  2415. ;fix list to add current names
  2416. temp$=playername$
  2417. exc.b=1
  2418. Gosub addname
  2419. temp$= compname$
  2420. exc=2
  2421. Gosub addname
  2422.  
  2423. ;fix scores
  2424. If gamedone=True
  2425.   For i=1 To entries
  2426.     If scorename$(i)=compname$
  2427.       gamesplayed(i)+1
  2428.       If cwon=True
  2429.         gameswon(i)+1
  2430.       EndIf
  2431.     EndIf
  2432.     If scorename$(i)=playername$
  2433.       gamesplayed(i)+1
  2434.       If pwon=True
  2435.         gameswon(i)+1
  2436.       EndIf
  2437.     EndIf
  2438.   Next
  2439. EndIf
  2440. ;figure % and sort arrays here ----
  2441. For i = 1 To entries
  2442.   If gamesplayed(i)
  2443.     won1.q=(gameswon(i)/gamesplayed(i))*100
  2444.     winpct(i)=Int(won1)
  2445.   Else
  2446.     winpct(i)=0
  2447.   EndIf
  2448. Next
  2449.  
  2450. Repeat             ;sort by number of games played first
  2451.   dummy=0
  2452.   For i = 1 To entries-1
  2453.     If gamesplayed(i)<gamesplayed(i+1)
  2454.       Gosub switchem
  2455.     EndIf
  2456.   Next
  2457. Until dummy=0
  2458.  
  2459.  
  2460. Repeat             ;now sort by winning %
  2461.   dummy=0
  2462.   For i = 1 To entries-1
  2463.     If winpct(i)<winpct(i+1) AND gamesplayed(i)=gamesplayed(i+1)
  2464.       Gosub switchem
  2465.     EndIf
  2466.   Next
  2467. Until dummy=0
  2468.  
  2469.  
  2470. If gamedone=True                   ;save scores to disk
  2471.   If WriteFile (0,"c8.scores")
  2472.     FileOutput 0
  2473.     If entries>30 Then entries=30
  2474.     NPrint entries
  2475.     For i = 1 To entries
  2476.       NPrint scorename$(i)
  2477.       NPrint gamesplayed(i)
  2478.       NPrint gameswon(i)
  2479.     Next
  2480.     CloseFile 0
  2481.     WindowOutput 0
  2482.   Else
  2483.     dummy=RTreq{"Disk Error",txt$(83),"OK"}
  2484.   EndIf
  2485. EndIf
  2486.  
  2487. ;now we'll make a listview to show the scores
  2488. Dim List MyList.scores(entries + 1)
  2489. For i = 1 To entries
  2490.   If AddItem(MyList())
  2491.     Format "000"
  2492.     temp$=scorename$(i)
  2493.     gp$=Str$(gamesplayed(i))
  2494.     gw$=Str$(gameswon(i))
  2495.     Format "###"
  2496.     wp$=Str$(winpct(i))
  2497.     Repeat
  2498.       temp$+Chr$(160)
  2499.       tl.w=TextLength_ (&rp,&temp$,Len(temp$))
  2500.     Until tl.w>96
  2501.     Repeat
  2502.       gp$+Chr$(160)
  2503.       tl=TextLength_ (&rp,&gp$,Len(gp$))
  2504.     Until tl>48
  2505.     Repeat
  2506.       gw$+Chr$(160)
  2507.       tl=TextLength_ (&rp,&gw$,Len(gw$))
  2508.     Until tl>52
  2509.     lis$=" "+temp$+gp$+gw$+wp$+"%"
  2510.     MyList()\string = lis$
  2511.   EndIf
  2512. Next
  2513. GTListView 2,51,0,0,290,160,"",0,MyList(),0,0
  2514. AddIDCMP #INTUITICKS
  2515. AddIDCMP #MOUSEMOVE
  2516. VWait
  2517. CacheClearU_
  2518. sctbl$=" "+txt$(86)
  2519. Window 2,10,20,300,173,$1000|$8,sctbl$,1,2
  2520. SubIDCMP #INTUITICKS|#MOUSEMOVE
  2521. MenusOff
  2522. AttachGTList 2,2
  2523. FlushEvents
  2524. Repeat
  2525.   ev.l=WaitEvent
  2526. Until ev=$200 OR ev=$40
  2527. DetachGTList 2
  2528. Free GTList 2
  2529. Free Window 2
  2530. Use Window 0
  2531. FlushEvents
  2532. Return
  2533.  
  2534. switchem
  2535. Exchange scorename$(i),scorename$(i+1)
  2536. Exchange gamesplayed(i),gamesplayed(i+1)
  2537. Exchange gameswon(i),gameswon(i+1)
  2538. Exchange winpct(i),winpct(i+1)
  2539. dummy=1
  2540. Return
  2541.  
  2542. .addname
  2543. gotim.b=False
  2544. For i = 1 To entries
  2545.   If temp$=scorename$(i)
  2546.     i=entries
  2547.     gotim=True
  2548.   EndIf
  2549. Next
  2550. If gotim=False
  2551.   entries+1
  2552.   scorename$(entries)=temp$
  2553.   Exchange scorename$(entries),scorename$(exc)
  2554.   Exchange gamesplayed(entries),gamesplayed(exc)
  2555.   Exchange gameswon(entries),gameswon(exc)
  2556.   ;If gamedone=0
  2557.   ;  gamesplayed(entries)=0
  2558.   ;  gameswon(entries)=0
  2559.   ;EndIf
  2560. EndIf
  2561.  
  2562. Return
  2563.  
  2564. FixBar           ;fix the damaged title bar
  2565.  
  2566. Use BitMap 0
  2567. Scroll 0,0,320,20,0,0,1
  2568. CacheClearU_
  2569. Use BitMap draw
  2570. Return
  2571.  
  2572. FixMode
  2573.   If ntsSys=True  ;original screen mode
  2574.     ForceNTSC
  2575.   Else
  2576.     ForcePAL
  2577.   EndIf
  2578. Return
  2579.  
  2580. ;card set selector
  2581.  
  2582. .newcards
  2583.  
  2584. carderr.b=0
  2585. titl$=" "+c8$+" "+txt$(80)
  2586. temp$=cardpic$
  2587. cardfi$=Peek.s(FilePart_(&cardpic$))
  2588. cardpic$= ASLFileRequest$ (titl$,cardpa$,cardfi$,0,12,320,188)
  2589. Gosub FixBar
  2590. If Exists (cardpic$) AND cardpic$<>""
  2591.   ILBMInfo cardpic$                       ;check the picture
  2592.   If ILBMWidth<>320 OR ILBMHeight<>200 OR ILBMDepth<>3       ;not even the right size!
  2593.     carderr=1
  2594.   EndIf
  2595. Else
  2596.   carderr=1
  2597. EndIf
  2598.  
  2599. If carderr=0
  2600.  
  2601.   Use Window 0
  2602.   setPointer {waitpointer,0}
  2603.   Message$=txt$(75)+" "+txt$(80)
  2604.   Gosub PrintMessage
  2605.   VWait 10
  2606.  
  2607.   Gosub grabcards
  2608.   CacheClearU_
  2609.   VWait
  2610.   CopyBitMap 0,1
  2611.  
  2612.   If setup=1 AND gamedone=False           ;fix the discard card
  2613.     Gosub Sorthand
  2614.     If CRank=8
  2615.       shp=60+CSuit
  2616.     Else
  2617.       shp=Pile(Dpile)
  2618.     EndIf
  2619.     Use BitMap see
  2620.     Blit shp,88,82
  2621.     Use BitMap draw
  2622.     Blit shp,88,82
  2623.   EndIf
  2624.  
  2625. Else                                      ;couldn't load the pic!
  2626.   noise=3
  2627.   Gosub makenoise
  2628.   If cardpic$<>""
  2629.     dummy=RTreq{txt$(60),txt$(81)+":|"+cardpic$,"OK"}
  2630.   EndIf
  2631. EndIf
  2632. If cardpic$="" Then cardpic$=temp$
  2633. Gosub openMenu
  2634. Return
  2635.  
  2636. .grabcards
  2637.  
  2638. If Exists (cardpic$)
  2639.   LoadBitMap 1,cardpic$                  ;load the pic
  2640.   column.w=0
  2641.   row.w=0
  2642.   Use BitMap 1
  2643.   CacheClearU_
  2644.   For shp=0 To 63                        ;OK, grab the shapes
  2645.     If shp<53 OR shp>58
  2646.       GetShape {shp,column,row,24,32}
  2647.       MidHandle shp
  2648.       column+25
  2649.       If column>250
  2650.         column=0
  2651.         row+33
  2652.       EndIf
  2653.     EndIf
  2654.   Next shp
  2655. Else
  2656.   rq$=txt$(81)+":"+Chr$(10)+cardpic$
  2657.   rq$+Chr$(10)+"Can't continue!"+Chr$(10)
  2658.   rq$+"Program ending..."
  2659.   dummy=RTEZRequest("ERROR!",rq$,"OK")
  2660.   End
  2661. EndIf
  2662.  
  2663. Return
  2664.  
  2665. .newfont
  2666.  
  2667. Free IntuiFont 0
  2668. LoadFont 0,font$,9
  2669. Return
  2670.